导航到根路由“/”

问题描述 投票:8回答:1

我试图从儿童路线导航到回家路线但没有任何反应。

即目前的路线是/projects

this.router.navigate(['/'])routerLink="/"都不起作用。

我的routerConfig看起来像这样

const routes: Routes = [
 {
   path: '',
   component: HomeComponent
 },
 {
   path: '/projects',
   component: ProjectsComponent
 }
]

我该怎么做呢?

angular typescript angular2-routing
1个回答
10
投票

尝试将redirectTo路由添加到您的路由配置:

const routes: Routes = [
    { path: '', redirectTo: 'home', pathMatch: 'full' },
    { path: 'home', component: HomeComponent },
    { path: 'projects', component: ProjectsComponent }
];
© www.soinside.com 2019 - 2024. All rights reserved.