0

this might be a duplicate, but I could not find the answer.

When I try to navigate to router with params, I get the following error: Error: Cannot match any routes. URL Segment: 'order/24'.

My router config is:

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}
    ]
  }
];

in the new-order component I try to navigate to order/:id:

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

I have already tried

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

Thanks for help.

2
  • Have you tried restarting the CLI? Commented Jun 14, 2017 at 14:16
  • yes, I have tried this Commented Jun 14, 2017 at 14:17

2 Answers 2

2

The problem is you defined path: 'pm', component: .., so all children of this route must start with pm. Try to navigate to route like this:

this.router.navigate(['/pm/order', this.orderId]);
Sign up to request clarification or add additional context in comments.

Comments

1

Try with

this.router.navigate(['./order', this.orderId],{
 relativeTo: this.route
});

Where this.route is an injected ActivatedRoute instance. Or you could go with the absolut path option with this.router.navigate(['/pm/order', this.orderId]).

  • ../ means that you go one level up in the route tree
  • ./ means sybling
  • / means absolut path, this.router.navigate(['/order', this.orderId]); would be root/order/:id for example

1 Comment

I have tried ../ and ./, without success: Error: Cannot match any routes. URL Segment: 'order/26'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.