With the route builder you can define and use search and path parameters with typing and validation.
You can also consume functions created with $api to securely exchange data with the server.
When you create a route in development mode, metadata will be automatically generated and you will have strong typing to access routes and their parameters in the Link component, the routePath function, and the RequestUrl class.
Also, in development mode, if you use filesystem routing with path params (ex: src/routes/users/[id].tsx) and you do not define the scheme for these params, a TypeScript warning will be raised.
Definition
title
Set a title to the page using the Title component of @solidjs/meta.
params
Define the parameters schema of the route.
By default, all parameters are used as search parameters, but you can use them in the path using the path option.
onParamsError
If an error occurs when validating parameters, you can choose to reset the parameters to a predefined valid value:
Or redirect to another page:
path
You can define the route path in two ways, using a fixed route without params (ex: /user?id=1):
Or by injecting part of the previously defined parameter scheme (ex: /user/1):
If you are creating the route under the file system (ex: /src/routes/users.tsx), you don’t need to define the path.
api
Injects API functions created with $api so they can be used in the component.
preload
Preloads data before accessing the route (default when hovering over the link).
create
Creates the route component with all the options previously entered.
The component receives an argument with the following properties:
params: the parameters of the route configured with the params option.
setParams: a function to set the search params of the route with type safe.
api: the API functions injected with the api option.