gpt4 book ai didi

javascript - Angular 路由器出现 404 错误?

转载 作者:行者123 更新时间:2023-11-30 15:05:16 25 4
gpt4 key购买 nike

我的问题是每次加载链接时。前任:“https://www.example.com/” 它将重定向到“https://www.example.com/design-brief” 因为我在我的 routing.ts 中配置了它。但是当我使用链接“https://www.example.com/design-brief”并在我的地址栏中输入时,它会在控制台日志中显示错误。“获取 https://www.example.com/design-brief 404 ()”

const APP_ROUTES: Routes = [
{ path: 'design-brief', component: DesignBriefComponent },
{ path: 'design-evaluation', component: DesignEvaluationComponent },
{ path: '', redirectTo: '/design-brief', pathMatch: 'full' },
{ path: "**",redirectTo:"/design-brief" } ];

这是我在 routing.ts 中的代码

最佳答案

参见 my answer here更详细地解释为什么会发生这种情况。

简而言之,您有 2 个选择:

  1. 将您的网络服务器配置为始终响应index.html 每当它检测到 404 - 这样,Angular 将始终负载及其路由服务将处理导航客户端。

  2. 将应用的 locationStrategy 更改为 Hash location strategy 作为描述 here .但是,这会更改您的应用程序的 URL,而且它是在我看来不是那么理想。

关于javascript - Angular 路由器出现 404 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45862243/

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