参数错误的angular2路由器

参数错误的angular2路由器,angular,angular2-routing,Angular,Angular2 Routing,这可能是重复的,但我找不到答案 当我尝试使用params导航到路由器时,我得到以下错误:错误:无法匹配任何路由。URL段:“订单/24” 我的路由器配置是: const routes: Routes = [ { path: 'pm', component: PmComponent, canActivateChild: [AuthGuard], children: [ {path: 'orderlist', component: OrderlistComponent

这可能是重复的,但我找不到答案

当我尝试使用params导航到路由器时,我得到以下错误:
错误:无法匹配任何路由。URL段:“订单/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}
    ]
  }
];
neworder
组件中,我尝试导航到
order/:id

this.router.navigate(['order/', this.orderId]);
我已经试过了

this.router.navigate(['/order/', this.orderId]);
谢谢你的帮助。

试试看

this.router.navigate(['./order', this.orderId],{
 relativeTo: this.route
});
其中,
this.route
是一个注入的
ActivatedRoute
实例。或者您可以使用带有
this.router.navigate(['/pm/order',this.orderId])的绝对路径选项

  • 。/
    表示您在路线树中向上走一层
  • /
    表示合成
  • /
    表示绝对路径,
    this.router.navigate(['/order',this.orderId])将是
    root/order/:id
尝试使用

this.router.navigate(['./order', this.orderId],{
 relativeTo: this.route
});
其中,
this.route
是一个注入的
ActivatedRoute
实例。或者您可以使用带有
this.router.navigate(['/pm/order',this.orderId])的绝对路径选项

  • 。/
    表示您在路线树中向上走一层
  • /
    表示合成
  • /
    表示绝对路径,
    this.router.navigate(['/order',this.orderId])将是
    root/order/:id

问题在于您定义了路径:'pm',组件:…
,因此此路由的所有子级必须以
pm
开头。尝试按如下方式导航到路线:

this.router.navigate(['/pm/order', this.orderId]);

问题是您定义了
路径:“pm”,组件:…
,因此此路由的所有子级必须以
pm
开头。尝试按如下方式导航到路线:

this.router.navigate(['/pm/order', this.orderId]);

您尝试过重新启动CLI吗?是的,我尝试过此操作您尝试过重新启动CLI吗?是的,我尝试过此操作我尝试过
。/
/
,但未成功:
错误:无法匹配任何路由。URL段:“订单/26”
我尝试了
。/
/
,但没有成功:
错误:无法匹配任何路由。URL段:“订单/26”