Usually on web sites, if you pay attention to a good user experience, you define a custom 404 page, telling the user he arrived at some dead end. Similarly we should do for our Angular application routing. In this lesson we learn how to define such “404 route” using the Angular router.
In the sample application, we have defined different kind of routes which we can navigate to by changing the URL up here. Now, what happens if the user types in some URL which doesn't exist? Our application redirects simply to the home, and nothing happens.
We want obviously to have a better user experience. Let's generate a new component. Let's call it notFound. Then we go to our app module, and at the very end here, we define a route that is going to catch all those routes which aren't matched.
We do that by defining here to asterisk. As a component, as you can imagine, we specify our notFound component. Let's open the notFound component, specify here, "Sorry, nothing to see here." Great. Let's save this.
Now, whenever we go to our routing component here, our normal routes just work. Where we a specify a route which doesn't exist, our component here, notFound, gets loaded and displays something nice to the user.
Member comments are a way for members to communicate, interact, and ask questions about a lesson.
The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io
Be on-Topic
Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.
Avoid meta-discussion
Code Problems?
Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context
Details and Context
Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!