Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

315
Views
Angular 4 - update route without appending another outlet's route to URL

I have a situation in Angular 4.0.3 where I have two <router-outlet>'s on a page.

<router-outlet></router-outlet>
<router-outlet name="nav"></router-outlet>

The first outlet will accept routes for content, and the second will accept routes for navigation. I achieve the navigation using this;

router.navigate(['', {outlets: { nav: [route] } }],{skipLocationChange: true });

This changes the outlet's contents without updating the URL - since I don't want any url that look like .. (nav:user).

The problem is the remaining outlet. I do want the URL to update when those are clicked, for instance ...

.../user/profile

Functionally, I can get both outlets to have the proper content, but it keeps appending the nav outlet's route to the url, like this ...

.../user/profile(nav:user)

Is there any way I can stop it from adding the (nav:user) part?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Unless there is some trick I'm not aware of ... I don't think you can. The address bar is what maintains the route state. So without the secondary outlet information in the address bar, the router won't know how to keep the correct routed component in the secondary outlet.

You could try overriding the navigateByUrl method as shown here: http://plnkr.co/edit/78Hp5OcEzN1jj2N20XHT?p=preview

export class AppModule {   constructor(router: Router) {
    const navigateByUrl = router.navigateByUrl;

    router.navigateByUrl = function(url: string|UrlTree, extras: NavigationExtras = {skipLocationChange: false}): Promise<boolean> {
      return navigateByUrl.call(router, url, { ...extras, skipLocationChange: true });
    }   } }

You could potentially add logic here then to check which routes you need to do this on.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!