Search code examples
angularangular-ui-routerangular2-routingangular8router

Why my router navigate function doesn't work in angular 8?


I'm trying to redirect to another component like this:

HomeComponent

  checkUrl(reference) {   
    if (reference != this.ref) {
      this.router.navigate(['/еrror']);
    }
  }

here is my router module

const routes: Routes = [
  { path: '', component: DefaultComponent },
  {
    path: '',
    children: [
      { path: ':dlr/:id/:ref', component: HomeComponent },
      { path: 'error', component: ErrorPageComponent },
    ]
  },
  { path: '**', redirectTo: '', pathMatch: 'full' }

];

right now I'm in the HomeComponent and want to go to the error page.

this.router.navigate(['/еrror']) this leads me to the DefaultComponent


Solution

  •  this.router.navigate(['/error'], { relativeTo: this.activatedRoute });
    

    adding relativeTo it worked for me.