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

226
Views
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 answers
Answer question

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 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!