Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

287
Visualizações
Angular secondary routes - Can't navigate & clear secondary route in the same navigate call?

I'm having an issue where it appears I can't navigate to a new route, and clear an outlet / secondary route at the same time.

Calling those two actions separately works - but feels like a workaround. Is there good reason why they should be done as two calls? Or is there an error in my implementation? Or should I file it as a GitHub issue?

These work independently:

// Navigate to `/second`
this._router.navigate(['/second']);

// Clears the `popup` outlet
this._router.navigate(['', {outlets: { popup: null }}]);

I thought this should work, but it doesn't clear the outlet:

this._router.navigate(['/second', {outlets: { popup: null }}]);

My current work-around is:

this._router.navigate(['', {outlets: { popup: null }}]).then(() => { this._router.navigate(['second']); } );

I've created a plnkr proof of concept - navigation code is in global-popup.component.ts

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You need to explicitly set primary outlet path like below,

public closeAndNav_singleCall() {
   return this._router.navigate([{
     outlets: { 
       primary : ['second'],
       popup: null 
     }
   }]);
}

Updated your Plunker!!

Hope this helps!!

over 4 years ago · Santiago Trujillo Relatório

0

The above works when the primary navigation is absolute on the primary route. The problem I am having is: how to do a relative navigation on the primary route, while clearing the secondary route.

I have tried different combinations but none seem to work:

starting at https://localhost:4200/one/two(popup:some/other)

    this.router.navigate([
      '',
      {
        outlets: {
          primary: ['areaTwo', 'second'],
          popup: null,
        },
      },
    ]);

ending at https://localhost:4200/areaTwo/second

So it clears the secondary popup, and it does an absolute navigation.

starting at https://localhost:4200/one/two(popup:some/other)

    this.router.navigate([
      {
        outlets: {
          primary: ['areaTwo', 'second'],
          popup: null,
        },
      },
    ], { relativeTo: this.activatedRoute });

ending at https://localhost:4200/one/two/areaTwo/second(popup:some/other)

So it does a relative on the primary, but does not clear the secondary.

But how can we do something like:

starting at https://localhost:4200/one/two(popup:some/other)

ending at https://localhost:4200/one/two/areaTwo/second

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda