[英]angular2 router with parameters error
這可能是重復的,但我找不到答案。
當我嘗試使用參數導航到路由器時,出現以下錯誤: Error: Cannot match any routes. URL Segment: 'order/24'
Error: Cannot match any routes. URL Segment: 'order/24'
。
我的路由器配置是:
const routes: Routes = [
{
path: 'pm', component: PmComponent, canActivateChild: [AuthGuard],
children: [
{path: 'orderlist', component: OrderlistComponent},
{path: 'new-order', component: NewOrderComponent},
{path: 'order/:id', component: OrderComponent},
{path: '**', component: PmDefaultComponent}
]
}
];
在new-order
組件中,我嘗試導航至order/:id
:
this.router.navigate(['order/', this.orderId]);
我已經嘗試過
this.router.navigate(['/order/', this.orderId]);
感謝幫助。
問題是您定義了path: 'pm', component: ..
,因此此路由的所有子代必須以pm
開頭。 嘗試導航到這樣的路線:
this.router.navigate(['/pm/order', this.orderId]);
試試看
this.router.navigate(['./order', this.orderId],{
relativeTo: this.route
});
其中this.route
是注入的ActivatedRoute
實例。 或者,您可以在this.router.navigate(['/pm/order', this.orderId])
使用絕對路徑選項。
../
表示您在路由樹中上一層 ./
表示sybling /
表示絕對路徑, this.router.navigate(['/order', this.orderId]);
例如將是root/order/:id
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.