Consider this scenario, if we navigate to the example.com/downloads and our route handler contains that route, the router handler will take the downloads component and place it into the placeholders of our page.
Setting Up for Routing
Now we are set up for routing, we have our route handler and a placeholder for the route handler to place components in.
Let’s try it. Since we do not have a component, create a component call downloads with the ng generate component command. Then set the component property of the route to the component.
Let’s verify that. Save the project and start the local server. Open the browser and go to localhost:4200/downloads.
As you can see, the contents in the downloads components is being displayed.
Go to the app-routing module file and add a wildcard route. To indicate that route is the wildcard route, we set the path property of the route with the double Asterix syntax. Lastly, use the error component for the component property.
As you can see, even though we did not define a route for downloads2, we still displayed something on the screen.
©2019 - 2023 Codeible. All rights reserved.