导航到根路由" /"

时间:2016-11-24 15:43:46

标签: angular typescript angular2-routing

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

即。当前路线为/projects

this.router.navigate(['/'])routerLink="/"都无效。

我的routerConfig看起来像这样

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

我该怎么做?

1 个答案:

答案 0 :(得分:9)

尝试在您的路线配置中添加redirectTo路线:

const routes: Routes = [
    { path: '', redirectTo: 'home', pathMatch: 'full' },
    { path: 'home', component: HomeComponent },
    { path: 'projects', component: ProjectsComponent }
];