Skip to content

createRoute

Creates new route. Has required parameter path

Basic example

ts
import { createRoute } from '@argon-router/core';

const route = createRoute({ path: '/route' });

route.open();

In-route path params

You can specify params in route path and argon-router outputs type in route object generic by typed-url-params library. Learn more about syntax

ts
import { createRoute } from '@argon-router/core';

const postRoute = createRoute({ path: '/post/:id' });
//       ^- Route<{ id: string }>

Parent paths

Sometimes you want to nest path parts and beforeOpen effects from some routes. You can do this easily with parent routes:

ts
import { createRoute } from '@argon-router/core';

const profile = createRoute({ path: '/profile/:id', beforeOpen: [] });

const friends = createRoute({ path: '/friends', parent: profile });
const posts = createRoute({ path: '/posts', parent: profile });

posts.open(); // profile.$isOpened -> true, posts.$isOpened -> true

API

nametypedescription
$paramsStore<T>route path parameters
$isOpenedStore<boolean>is route opened (note: route opened if his child opened too)
$isPendingStore<boolean>is route open pending (if before open in progress)
openEventCallable<RouteOpenedPayload<T>>open route and it's parents
openedOnServerEvent<RouteOpenedPayload<T>>route opened on server (SSR)
openedOnClientEvent<RouteOpenedPayload<T>>route opened on client
openedEvent<RouteOpenedPayload<T>>route opened on server (SSR) or client
closedEvent<void>route closed
pathstringroute path
parentRoute<any>parent path
beforeOpenEffect<any, any>[]before open effects

Released under the MIT License.