我正在关注Angular2 路线教程。我正在尝试将默认路由器“”重定向到“enderecamento”,但在控制台上出现此错误:
我的路由代码如下:
app.routing.ts:
export const appRoutingProviders: any[] = [
];
const pecaJuridicaRoutes: Routes = [
{
path: '',
redirectTo: 'pecaJuridica',
pathMatch: 'full'
},
{
path: 'pecaJuridica',
component: PecaJuridicaComponent,
pathMatch: 'full',
children: [
{ path: 'enderecamento', component: EnderecamentoComponent,},
{ path: '', redirectTo: 'enderecamento', pathMatch: 'full' }
]
},
];
console.log(pecaJuridicaRoutes);
const appRoutes: Routes = [
...pecaJuridicaRoutes,
];
export const routing = RouterModule.forRoot(appRoutes);
奇怪的是,如果我改变:
[...]
children: [
{ path: 'enderecamento', component: EnderecamentoComponent,},
{ path: '', redirectTo: 'enderecamento', pathMatch: 'full' }
]
[...]
对此:
[...]
children: [
{ path: 'enderecamento', component: EnderecamentoComponent,},
{ path: '', component: EnderecamentoComponent, }
]
[...]
'enderecamento' 页面已加载,但如果 iIclick 页面中的 routerLink 以重定向它或在上下文 'pecaJuridica/enderecamento' 上写入,我得到相同的 Uncaught promise [object Object] 错误,有没有办法调试它?这非常令人沮丧,因为我知道这一定是一件简单的事情,而且这些错误消息对我来说并不直观......
一些附加信息:
重定向plnkr:
重定向 routerLink plnkr:
路由器链接html代码:
[...]
<ul class="sidebar-nav" id="sidebar">
<li>
<a routerLink="enderecamento" routerLinkActive="focus" *ngFor="let button of buttons; let index = index">
<span >{{button.label}}</span>
<span class="sub_icon glyphicon {{button.class}}" >
</span>
</a>
</li>
</ul>
[...]