Routes without URLs
A route can exist without a path. Modals, wizard steps and native screens are routes too — assign URLs later, in one place.
createVirtualRoute
Model navigation as state and events — then render it anywhere.
import { beforeNavigate, chainRoute } from '@effector/router'
import { sample } from 'effector'
// Hold navigation until the guard resolves
const guard = beforeNavigate({
controls,
to: dashboardRoute,
filter: $unauthorized,
})
sample({
clock: guard.started,
target: redirect({ to: loginRoute }),
})
// Open the route only after data is ready
const readyDashboard = chainRoute({
route: dashboardRoute,
beforeOpen: loadDashboardFx,
})NAVIGATION IS STATE
Every route is an Effector unit. Change the URL or open a route — the graph and every store update in lockstep. This is state you can observe, combine and test, not a side effect of rendering.
routes
stores
router.$path/feedRoute.$isOpenedfalsepostRoute.$isOpenedfalseprofileRoute.$isOpenedfalsesettingsModal.$isOpenedfalsenone.$params{}events
open a route to fire opened / closed
THE CORE IDEA
In most routers a route is a URL. Here a route is a unit of state and events that may or may not have a path. Modals, wizard steps and native screens become first-class routes — and the URL is just one adapter you plug in later.
createRoute() works with no path at all.// A modal is a route with no URL
const settingsModal = createRoute()
// A screen is a route with a typed path
const userRoute = createRoute({
path: '/user/:id',
}) // Route<{ id: string }>
// URLs live in one place — the router
const router = createRouter({
routes: [
userRoute,
{ path: '/settings', route: settingsModal },
],
})HOW IT DIFFERS
Most routers treat a route as a URL, and navigation as a side effect of rendering. Here a route is an Effector unit — so navigation is state you can observe, combine and test without a DOM.
Most routers
@effector/router
sampleNot a replacement for react-router or TanStack Router — a different answer for apps already modelling logic in Effector.
CHOOSE YOUR PATH