Config-based routing
Edit this pageSolid Router allows for configuration-based routing, where JSX is not needed to set up routes.
To define a single route, a route definition object can be passed to the <Router>
component:
In the route definition object, a path
property must be provided to define the path to match and a component
property that specifies the component (or element) to render when the path matches.
To define multiple routes, an array of route definition objects can be passed to the <Router>
] component:
Each path in the array of route definition objects will be matched against the current URL, and the corresponding component will be rendered when a match is found.
In the example above, the root path (/
) renders the Home
page, the path /hello-world
renders an h1
element, and the path /about
renders the About
component.
When using configuration-based routing, it is best practice to use the lazy
component to load components asynchronously.
This will help improve the performance of your application by only loading the components when they are needed.
To learn more about lazy loading, see the page on lazy loading components.