Angular Router获取404 Bug? [英] Angular Router Get 404 Bug?
问题描述
我的问题是每次加载链接时。例如:
https://www.example.com/ 它将重定向到
https://www.example.com/design-brief 因为我在我的routing.ts中配置它。
但是当我使用链接 https://www.example.com/design-简短并输入我的地址栏,它将在控制台日志中显示错误。
获取 https://www.example.com/design-brief 404 ()
My problem is that every time I load my link. Ex: "https://www.example.com/" it will redirect to "https://www.example.com/design-brief" since I configured it in my routing.ts. But when I will use the link "https://www.example.com/design-brief" and enter in my address bar, it will show an error in console log. "GET 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中的代码
Here is my code in my routing.ts
推荐答案
请参阅我的答案,以获取更详细的解释原因。发生。
See my answer here for a more detailed explanation of why this is happening.
简而言之,您有两种选择:
In a nutshell, you have 2 options:
-
将Web服务器配置为每当检测到404时始终使用
index.html进行响应 - 这样,Angular将始终为
加载,其路由服务将处理
客户端上的导航。
Configure your web server to always respond with the index.html whenever it detects a 404 - that way, Angular will always load and its routing service will handle the navigation on the client side.
将应用的locationStrategy更改为Hash位置策略,因为
描述了这里。但是,这会改变你的应用程序的URL,而且我认为这不是我想要的
。
Change your app's locationStrategy to the Hash location strategy as described here. However, that would change your app's URLs, and it's not that desirable in my opinion.
这篇关于Angular Router获取404 Bug?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!