0

I'm on a view with the current route:

http://localhost:4200/#/corp/projects/detail/05940c57/page1

And I want to get to

http://localhost:4200/#/corp/projects/detail/05940c57/page2

Is there a way to change to "page2" using navigate() or navigateByUrl()?

2 Answers 2

1

You can use relativeTo:

constructor (
  private activatedRoute: activatedRoute,
  private router: Router
) { }

myFunc() {
  this.router.navigate(['page2'], { relativeTo: this.activatedRoute });
}
Sign up to request clarification or add additional context in comments.

Comments

0

It's not clear how did you arrive to the first URL, but assuming you have a configuration like

  {path: 'detail/:id/:page', component: ProjectDetailComponent}

you can navigate to it as follows:

export class AppComponent {

  constructor (private router: Router) {}

  onClick () {
    this.router.navigate(['/detail', '05940c57', 'page2']);
  }
}

2 Comments

The configuration is more like: {path: 'detail/:id', component: ProjectNavigationComponent, children: [{path:'revenue', component:RevenueModelComponent}, {path:'load', component:SystemLoadComponent}]}
then navigate() should be called in the RevenueModelComponent

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.