Description Type-safe route builder.
With the route builder you can define and use search and path parameters
with typing and validation.
You can also consume functions created with the API builder ($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.
Import import { $route } from " dreamkit " ;
Definition params : ( value : object ) => typeof $route ;
path : ( value : string | ( ( params : object ) => string ) ) => typeof $route ;
value : ( data : { intent : string ; params : object } ) => any ,
setParams : ( value : object ) => void ;
Examples Path param import { $route, Link, s } from " dreamkit " ;
export const homeRoute = $route . path ( " / " ) . create ( () => (
< Link href = " /user/:id " params ={{ id: 1 }}>
< Link href = " /user/:id " params ={{ id: 2 }}>
export const userRoute = $route
. params ({ id: s . number () })
. path ( ( params ) => ` /user/ ${ params . id } ` )
. create ( ( { params } ) => <>id: {params.id} </> );
Optional path params import { $route, Link, s } from " dreamkit " ;
export const homeRoute = $route . path ( " / " ) . create ( () => (
< Link href = " /section " > link without params </ Link >
< Link href = " /section " params ={{ name: " test " }}>
export const sectionRoute = $route
. params ({ name: s . string () . optional () })
. create ( ( { params } ) => <>name: {params.name} </> );
Synced search params import { Input, $route, s } from " dreamkit " ;
. create ( ( { params , setParams } ) => {
< i >Look at the address bar of your browser .</ i >
value = {params.name ?? "" }
setParams ( { ... params , name: name || undefined } )
placeholder = " country code "
value = {params.country?.code ?? "" }
country: { ... params . country , code: code || undefined },