Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

319
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda