Alex
Alex

Reputation: 1

Angular 5 - navigate to the same route with different parameter,

Im trying to navigate to same route with different params, but its redirect me to to my ' ' route. When i'm pressing the back button its showing me the right page. any help....

My routes:

const appRoutes: Routes = [
  { path: '', component: IndexComponent },
  // .......
  {
    path: 'projects',    
    component: ProjectsComponent, 
    canActivate: [ AuthGuardService ], 
    children: [
      { path: 'details/:id', component: ProjectDetailsComponent }
    ]
  }
];

My navigation option

this.router.navigate(['/projects/details/',project.projectId ]);

At ProjectDetails i got :

this.route.params.subscribe((params:any) => {
  this.currentProjectId = params['id'];
  this.getProject();
});

Upvotes: 0

Views: 1375

Answers (1)

ForestG
ForestG

Reputation: 18085

Try this:

this.router.navigate(['projects', 'details' ,project.projectId ]);

If this still redirects you, then there is a navigate around ProjectDetailsComponent's ngOnInit,

or, maybe your route guard AuthGuardService canActivate is not fulfilled at the time of the routing event. (debug the canActivate)

Upvotes: 1

Related Questions