To create a DoksJS route, you need to create a JavaScript object that specifies the route's path, component, and other options.
Here is an example of a DoksJS route that defines a home page:
This route specifies that the home page is located at the root path (/
) and that the HomeComponent
component will be used to render the page.
To add a route to your application, you need to add it to the routes
property of the App
component.
Here is an example of an App
component that adds the home route:
This code will add the home route to the application. When the user navigates to the root path (/
), the HomeComponent
component will be rendered.
You can also create routes that have parameters. 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"
:
This code will navigate to the /users/John Doe
path, which will render the UserComponent
component with the name
prop set to "John Doe"
.