Routing is a very powerful concept in Angular and the @angular/router library package enables navigation from one component to another as the user performs application tasks.
We define routes in AppRoutingModule in Angular with a related component like below
In the above example, if the route path "first-component" is hit then FirstComponent Component will be loaded in the browser similarly route path "second-component" is hit then SecondComponent will be loaded in the browser.
In some cases, we require dynamic routing in Angular and it's not possible to mention every route in the Route array of AppRoutingModule.
Today we are going to look at how can we configure dynamic routing in the Angular
In the above route configuration whenever we hit the browser article/id/"anything-in-route" it will load ArticleComponent in the browser.
Please note id can be any number or identifier through which you can load the data from the backend.
In ArticleComponent you can get the id and title on ngOnit method as below.
Hope you have enjoyed the article.