...

/

Route Parameters

Route Parameters

Let's explore how we can use route parameters to pass an ID or parameter as part of the URL and load data based on that parameter.

A very common part of any modern web application is passing an ID or parameter as part of the URL to load data based on that parameter. In Angular, this is achieved using Route parameters.

What are Route parameters?


Route parameters are dynamic values that are attached to the end of a URL. This value is then used to load data or a flag in the view to change how a view will look.


You would probably use this to load in the details of a specific client or company, something we will be doing once we have built up the application enough to start saving data.

Example

For example, here is a standard URL: http://localhost:4200/clients. A URL with a parameter on the end of it would look like this: http://localhost:4200/client/24. The difference is that at the end of the second URL is a number, which could be the ID of a Client whose details we want to load. This is something we will be doing in the next chapter.

Setting up a route to handle parameters

In order to access this ID, we need to add a route that is able to handle the fact that the ID is part of the URL. To do ...