Navigation and parameters
In BooksStore
, for example, the user can see a list of books on the Index page, but the user should also be able to click on a book and navigate to another page where all the book details are visible. When we navigate to the details page, we need to pass the book ID to it so that the page knows the book for which the details need to be retrieved.
Luckily, Blazor provides us with powerful and flexible routing and navigation mechanisms that allow us to navigate easily and send data in the URL, either by using the route of the page itself or using query parameters. We are going to explain both in detail.
Passing parameters using the route
Parameters can be sent within the route of the page. The Router
component is responsible for detecting those parameters and filling in the values from the URL for the parameters in the targeted component based on the parameter name.
In the next example, we are going to create a BookDetails
component and set a route...