4

I searched over and over again, but maybe my search terms were incorrect, because nothing turned up. I want to dynamically show my 404 component depending on the results of an HTTP request.

I realize that I can do this by redirect the user to my 404 page, but is there any way I can render the component without changing the URL?

Something like /people/<nonexistent id>

  1. Perform HTTP request
  2. If person exists, proceed as normal
  3. If person doesn't exist, render 404 without changing the URL

Thank you!

1 Answer 1

10

Never mind, I found the answer.

The solution is to userouter.navigate with the option skipLocationChange set to true. This tells Angular to reroute without changing the URL in the browser navbar.

https://angular.io/api/router/NavigationExtras#skipLocationChange

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.