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

224
Visualizações
Angular Routing: Keep NavigationError url

Currently in Angular 4, if I'm trying to verify this route is working:

/my/long/route

If I go to it directly and it throws an error, the Router will update the url to /, since no valid routes have loaded. If I navigate to the error throwing route in the application, the url is set to the last route that worked.

Is there a way I can keep the url set on the failed route url? From an error logging perspective, it would be nice if I could just use the actual url the user was on opposed to fishing for it in the router events, and for local debugging it would be nice to be able to refresh the page opposed to needing to navigate back to it every time.

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

0

Based on the source code:

https://github.com/angular/angular/blob/410aa33005f2dc6f6500db71e7f019a744f909d9/packages/router/src/router.ts#L750

I don't really see a way of getting around the issue.

For now I'm just going to do this (which has it's own set of problems):

    this.router.events.subscribe(event => {
        if (event instanceof NavigationError) {
            this.routeFailed = true;
            setTimeout(() => this.location.replaceState(event.url));
        } else {
            this.routeFailed = false;
        }
    });
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