[英]Angular rerouting to home page doesn't work?
Here is my error: 这是我的错误:
core.es5.js:1020 ERROR Error: Uncaught (in promise):
Error: Cannot match any routes. URL Segment: 'home'
This is the code from the view.html: 这是view.html中的代码:
<div class="container">
This is the main app;
<a routerLink="second">Click to go to second</a>
<a routerLink="third">Click to go to third</a>
<a routerLink="app">Go to Home</a>
<router-outlet></router-outlet>
</div>
And this is my array of objects which includes the path to the home and other paths. 这是我的对象数组,其中包括到家的路径和其他路径。 The path to the home is correct, hence I don't see why the error pops up every time I click on it. 到家的路是正确的,因此我不明白为什么每次单击它时都会弹出错误。
const appRoutes: Routes=[
{path:'second', component:SecondComponent},
{path:'third', component:ThirdComponent},
{path:'', redirectTo:'./app', pathMatch:'full'},
]
When I click on the third and second component url, everything works fine. 当我单击第三个和第二个组件URL时,一切正常。
NOTE: I want to hide the second and third component when I click on the home component. 注意:单击主页组件时,我想隐藏第二个和第三个组件。
You need to define the home route: 您需要定义本国路线:
const appRoutes: Routes=[
{path:'home', component:HomeComponent},
{path:'second', component:SecondComponent},
{path:'third', component:ThirdComponent},
{path:'', redirectTo:'/home', pathMatch:'full'},
{path:'**', redirectTo:'/home', pathMatch:'full'}
];
This solves my problem, my home path is empty and therefor the home page does not duplicate itself once I click on the home tag. 这解决了我的问题,我的主页路径为空,因此一旦单击主页标签,主页就不会重复自身。
const APP_ROUTES: Routes=[
{path:'first', component:FirstComponent},
{path:'second', component:SecondComponent},
{path:'third', component:ThirdComponent},
{path:'', redirectTo:'', pathMatch:'full'},
];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.