我正在尝试从子路线导航到主路线,但没有任何反应。
即当前路线是/projects
this.router.navigate(['/'])
和 routerLink="/"
都不起作用。
我的 routerConfig
看起来像这样
const routes: Routes = [
{
path: '',
component: HomeComponent
},
{
path: '/projects',
component: ProjectsComponent
}
]
我该怎么做?
最佳答案
尝试将 redirectTo
路由添加到您的路由配置中:
const routes: Routes = [
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'home', component: HomeComponent },
{ path: 'projects', component: ProjectsComponent }
];
关于angular - 导航到根路由 "/",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40790307/