gpt4 book ai didi

javascript - 当在浏览器中重新加载 URL 到定义的路由器路由时出现 404

转载 作者:行者123 更新时间:2023-12-03 01:33:02 25 4
gpt4 key购买 nike

我在产品服务器上上传了我的 Angular 4 应用程序,该应用程序在本地完美运行。在服务器上,我可以通过链接访问页面,但是,如果我尝试直接在浏览器中写入 url,我的页面会转到 404。我红色表示我可以通过 .htacces 解析,但它不是 apache 服务器,所以我不能。是否有唯一的前端解决方案来解决问题?

最佳答案

Angular 中使用的默认客户端路由策略是 PathLocationStrategy .

如果您手动输入 URL,则需要将服务器配置为针对请求的所有不同 URL 返回相同的页面。这个策略需要服务器端的一些配合。

Is there a frontend solution to resolve the problem?

使用HashLocationStrategy

HashLocationStrategy uses the hash fragment part of the URL to store state for the client, it easier to setup and doesn’t require any co-operation from the server side but has the downside that it won’t work with Angular Universal once that’s released.

@NgModule({
imports: [
BrowserModule,
FormsModule,
RouterModule.forRoot(routes, { useHash: true }) //enable hashbang approach
],

Location Strategies in Angular Router

Which strategy is best?

关于javascript - 当在浏览器中重新加载 URL 到定义的路由器路由时出现 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51195015/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com