Skip to content

useRoute

import { useRoute } from "dreamkit";

Use route config without having to create the component with the route builder.


Definition

import type { Route } from "dreamkit";
const useRoute: (route: Route) => {
setParams: (params: object) => void;
params: object;
api: Record<string, Function>;
data: any;
};

Examples

Example 1

import { $route, useRoute, s, Link } from "dreamkit";
export const route = $route.params({
id: s.number().optional(),
});
export default function Home() {
const { params } = useRoute(route);
return (
<>
<Link href="/" params={{ id: 1 }}>
id: 1
</Link>
<br />
<Link href="/">id: undefined</Link>
<br />
<div>id: {params.id}</div>
</>
);
}