Skip to content

routePath

Description

Utility function to construct a routing path along with its parameters.

Import

import { routePath } from "dreamkit";

Definition

declare const routePath: (path: string, params?: Record<string, any>) => string;

Examples

Basic usage

import { $route, routePath, s } from "dreamkit";
export const userRoute = $route
.params({ id: s.number() })
.path(({ id }) => `/user/${id}`)
.create(({ params }) => <>id: {params.id}</>);
export default $route.path("/").create(() => {
return <a href={routePath("/user/:id", { id: 1 })}>User 1</a>;
});