createRouter() function
Home > @rimitive/router > createRouter
createRouter() function
Section titled “createRouter() function”Create a router instance
Signature:
export declare function createRouter(deps: RouterDeps, routes: RouteConfig[], options?: RouterOptions): Router;Parameters
Section titled “Parameters”|
Parameter |
Type |
Description |
|---|---|---|
|
deps |
Signal primitives from @rimitive/signals | |
|
routes |
Route configuration (pure data) | |
|
options |
(Optional) Router options |
Returns:
Example
Section titled “Example”import { createRouter } from '@rimitive/router';
const routes = [ { id: 'home', path: '' }, { id: 'about', path: 'about' }, { id: 'products', path: 'products', children: [ { id: 'product-detail', path: ':id' } ]}];
const router = createRouter({ signal, computed }, routes);
// Use in view layermatch(router.matches, (matches) => { const route = matches[0]; if (!route) return NotFound(); return componentMap[route.id]({ params: route.params });});