我的RouteConfig定义了以下路径
@RouteConfig ([
{ path:'/main',name:'Home',redirectTo: ['Setup']},
{ path:'/setup',name:'Setup',component:SetupComponent},
{ path:'/configuration',name:'Configuration',component:ConfigurationComponent},
])
在我的模板中
<ol>
<li><a [routerLink]="['Setup']">Setup</a></li>
<li><a [routerLink]="['Configuration']">Configuration</a></li>
<li><a [routerLink]="['Home']">Home</a></li>
</ol>
在组件中,我尝试过一种方法
this._Router.navigate(['Home']);
在这两种情况下,(使用routerLink指令和Router.navigate方法)在尝试导航到“Home”路由时,我收到以下错误 .
Component "AppComponent" has no route named "Home"
而具有与其关联的组件的路线都按预期工作 . 从Children路由器调用它们时的行为也是如此 .
如何路由/导航到名为“Home”的路由?
2 回答
您无法为重定向路由指定名称 . 由于
Home
重定向到名为Setup
的路由,因此我将使用Setup
名称 .你应该使用/之前的路由器名称this._Router.navigate(['/ Home']);
在Routing through links in Angular2看另一个例子