angularurlnavigateurl

I want to navigate when i click button but i got this error


onMenuSelect(event:any){

if(event.actionName == 'VD'){
  this.rout.navigateByUrl('/scientific-departments');
}

} ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'scientific-departments' Error: Cannot match any routes. URL Segment: 'scientific-departments' at ApplyRedirects.noMatchError (router.js:4396) at CatchSubscriber.selector (router.js:4360) at CatchSubscriber.error (catchError.js:29) at MapSubscriber._error (Subscriber.js:75) at MapSubscriber.error (Subscriber.js:55) at MapSubscriber._error (Subscriber.js:75) at MapSubscriber.error (Subscriber.js:55) at MapSubscriber._error (Subscriber.js:75) at MapSubscriber.error (Subscriber.js:55) at ThrowIfEmptySubscriber._error (Subscriber.js:75) at resolvePromise (zone-evergreen.js:798) at resolvePromise (zone-evergreen.js:750) at zone-evergreen.js:860 at ZoneDelegate.invokeTask (zone-evergreen.js:399) at Object.onInvokeTask (core.js:41632) at ZoneDelegate.invokeTask (zone-evergreen.js:398) at Zone.runTask (zone-evergreen.js:167) at drainMicroTaskQueue (zone-evergreen.js:569) at ZoneTask.invokeTask [as invoke] (zone-evergreen.js:484) at invokeTask (zone-evergreen.js:1621)


Solution

  • The route you trying to navigate is not registered. Can you provide more details? how you defined the routes? provide some code from your routing module where you added the route.

    Better use navigate with relative to current route extra options instead of navigateByUrl.

    this.route.navigate(['scientific-departaments'], {relativeTo: this.route})