Skip to content

Router API ​

This page is an index of the public @elfui/router API. See the Router guide for full examples.

Creation and history ​

ts
createRouter(options): Router
createWebHistory(base?): RouterHistory
createWebHashHistory(base?): RouterHistory
createMemoryHistory(base?): RouterHistory
setActiveRouter(router | null): void
getActiveRouter(): Router | null

TIP

RouterOptions accepts routes, history (preferred) or mode, plus initialPath, sensitive, strict, scrollBehavior, linkActiveClass, and linkExactActiveClass.

Router instance ​

MemberDescription
current, currentRouteReactive refs containing the current RouteLocation.
push(to), replace(to)Navigate and resolve to void or NavigationFailure.
back(), forward(), go(delta)Traverse history.
resolve(to, currentLocation?)Resolve without navigating.
beforeEach, beforeResolve, afterEach, onErrorRegister hooks; each returns an unregister function.
addRoute, removeRoute, clearRoutes, hasRoute, getRoutesChange or inspect route records.
isReady()Resolve after initial navigation, guards, and lazy page loading.
listeningWhether browser history events are observed.

Elements and composables ​

registerRouterElements() registers <elf-router-view>, <elf-router-link>, and the <elf-link> alias. useRouter() returns the active Router or null; useRoute() returns a stable readonly current location; useLink() supplies headless link behavior. onBeforeRouteLeave() and onBeforeRouteUpdate() register component guards.

Utilities and types ​

parseQuery(), stringifyQuery(), isNavigationFailure(), and NavigationFailureType are exported helpers. The main types are Router, RouterOptions, RouterHistory, RouteRecord, RouteLocation, RouteLocationRaw, RouteQuery, NavigationGuard, NavigationFailure, and ScrollBehaviorFn.