API Reference

Core API

createRouter

Create a router instance

const router = createRouter([routes], [options], [dependencies])

cloneRouter

Clone an existing router.

const clonedRouter = cloneRouter(router, dependencies)
  • router: the router instance to clone

  • dependencies: the new dependencies, for the cloned router (optional)

add

Add routes, see defining routes

router.add(routes)

start

  • startPathOrState: a starting path (string) or state (object). When using browserPlugin, this argument is optional: path will be read from the document location

  • done: a done callback (done(err, state))

isStarted

Check if the router is in a started state

Navigate to a new route

  • routeName: the name of the route to navigate to

  • routeParams: the route params

  • options: options for the transition (replace, reload, skipTransition, force or any custom option)

  • done: a done callback (done(err, state))

Navigate to the default route (if any)

Stop

Stop your router

cancel

Cancel the current transition (if any)

forward

Set a route to forward to another route (when navigating to the first one)

getState

Return the current state

getOptions

Return current options

setOption

Set an option

setDependency

Set a dependency

setDependencies

Set dependencies

getDependencies

Return the current dependencies

useMiddleware

Register one or multiple middlewares, see middleware

clearMiddleware

Remove all middleware

usePlugin

Register one or multiple plugins, see plugins

canActivate

Set a canActivate handler for the provided route name, see preventing navigation

canDeactivate

Set a canDeactivate handler for the provided route name, see preventing navigation

clearCanDeactivate

Remove a canDeactivate handler for the provided route name

buildPath

Build a path given a route name and params

matchPath

Attempt to match a path

setRootPath

Set the root path

isActive

Check if the provided route is currently active

  • name: the route name

  • params: the route params

  • strictEquality: whether to check if the given route is the active route, or a descendant of the active route (false by default)

  • ignoreQueryParams: whether to ignore query params (true by default)

areStateEqual

Compare two route state objects

areStatesDescendants

Check if a state is a descendant of another state

Browser plugin

See in the browser

The browser plugin adds the following to your router instance:

buildUrl

Build an URL

matchUrl

Match an URL

replaceHistoryState

Replace state in history and silently update your router instance state. Use if you know what you are doing.

Last updated