To define a parameter, you need to use the :
character before the parameter name. For example, the following route defines a route that takes a name
parameter:
This route specifies that the user page is located at the /users/:name
path and that the UserComponent
component will be used to render the page. The :name
parameter will be passed to the UserComponent
component as a prop.
To use a route with a parameter, you need to pass the value of the parameter to the route's path. For example, the following code will navigate to the user page for the user with the name "John Doe"
:
Here are some additional tips for using parameters in DoksJS:
You can use the
params
property of the route's component to access the parameters that were passed to the route.You can use the
matchPath()
method to check if a path matches a route with parameters.You can use the
redirect
property to redirect the user to a different route when a route is navigated to with invalid parameters.