API Reference

Core API

createRouter

Create a router instance
1
const router = createRouter([routes], [options], [dependencies])
Copied!

cloneRouter

Clone an existing router.
1
const clonedRouter = cloneRouter(router, dependencies)
Copied!
  • router: the router instance to clone
  • dependencies: the new dependencies, for the cloned router (optional)

add

Add routes, see defining routes
1
router.add(routes)
Copied!

start

1
router.start(startPathOrState, [done])
Copied!
  • 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
1
router.isStarted()
Copied!
Navigate to a new route
1
router.navigate(routeName, [routeParams], [options], [done])
Copied!
  • 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)
1
router.navigateToDefault([opts], [done])
Copied!

Stop

Stop your router
1
router.stop()
Copied!

cancel

Cancel the current transition (if any)
1
router.cancel()
Copied!

forward

Set a route to forward to another route (when navigating to the first one)
1
router.forward(fromRoute, toRoute)
Copied!

getState

Return the current state
1
const state = router.getState()
Copied!

getOptions

Return current options
1
router.getOptions()
Copied!

setOption

Set an option
1
router.setOption(name, value)
Copied!

setDependency

Set a dependency
1
router.setDependency(dependencyName, dependency)
Copied!

setDependencies

Set dependencies
1
router.setDependencies(dependencies)
Copied!

getDependencies

Return the current dependencies
1
const dependencies = router.getDependencies()
Copied!

useMiddleware

Register one or multiple middlewares, see middleware
1
const remove = router.useMiddleware(...middlewares)
Copied!

clearMiddleware

Remove all middleware
1
router.clearMiddleware()
Copied!

usePlugin

Register one or multiple plugins, see plugins
1
const teardown = router.usePlugin(...plugins)
Copied!

canActivate

Set a canActivate handler for the provided route name, see preventing navigation
1
router.canActivate(name, canActivateHandler)
Copied!

canDeactivate

Set a canDeactivate handler for the provided route name, see preventing navigation
1
router.canDeactivate(name, canDeactivateHandler)
Copied!

clearCanDeactivate

Remove a canDeactivate handler for the provided route name
1
router.clearCanDeactivate(name)
Copied!

buildPath

Build a path given a route name and params
1
router.buildPath(route, params)
Copied!

matchPath

Attempt to match a path
1
router.matchPath(path, [source])
Copied!

setRootPath

Set the root path
1
router.setRootPath(rootPath)
Copied!

isActive

Check if the provided route is currently active
1
router.isActive(name, params, [strictEquality], [ignoreQueryParams])
Copied!
  • 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
1
router.areStatesEqual(state1, state2, ignoreQueryParams)
Copied!

areStatesDescendants

Check if a state is a descendant of another state
1
router.areStatesDescendants(parentState, childState)
Copied!

Browser plugin

The browser plugin adds the following to your router instance:

buildUrl

Build an URL
1
router.buildUrl(routeName, routeParams)
Copied!

matchUrl

Match an URL
1
router.matchUrl(url)
Copied!

replaceHistoryState

Replace state in history and silently update your router instance state. Use if you know what you are doing.
1
router.replaceHistoryState(name, params)
Copied!
Last modified 3yr ago