[英]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.