Comment on page
API Reference
Create a router instance
const router = createRouter([routes], [options], [dependencies])
dependencies
: the dependencies you want to make available in middleware and plugins, see dependency injection
Clone an existing router.
const clonedRouter = cloneRouter(router, dependencies)
router
: the router instance to clonedependencies
: the new dependencies, for the cloned router (optional)
router.add(routes)
router.start(startPathOrState, [done])
startPathOrState
: a starting path (string) or state (object). When usingbrowserPlugin
, this argument is optional: path will be read from the document locationdone
: a done callback (done(err, state)
)
Check if the router is in a started state
router.isStarted()
Navigate to a new route
router.navigate(routeName, [routeParams], [options], [done])
routeName
: the name of the route to navigate torouteParams
: the route paramsoptions
: 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)
router.navigateToDefault([opts], [done])
Stop your router
router.stop()
Cancel the current transition (if any)
router.cancel()
Set a route to forward to another route (when navigating to the first one)
router.forward(fromRoute, toRoute)
Return the current state
const state = router.getState()
Return current options
router.getOptions()
Set an option
router.setOption(name, value)
Set a dependency
router.setDependency(dependencyName, dependency)
Set dependencies
router.setDependencies(dependencies)
Return the current dependencies
const dependencies = router.getDependencies()
const remove = router.useMiddleware(...middlewares)
Remove all middleware
router.clearMiddleware()
const teardown = router.usePlugin(...plugins)
router.canActivate(name, canActivateHandler)
router.canDeactivate(name, canDeactivateHandler)
Remove a
canDeactivate
handler for the provided route namerouter.clearCanDeactivate(name)
Build a path given a route name and params
router.buildPath(route, params)
Attempt to match a path
router.matchPath(path, [source])
Set the root path
router.setRootPath(rootPath)
Check if the provided route is currently active
router.isActive(name, params, [strictEquality], [ignoreQueryParams])
name
: the route nameparams
: the route paramsstrictEquality
: 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)
Compare two route state objects
router.areStatesEqual(state1, state2, ignoreQueryParams)
Check if a state is a descendant of another state
router.areStatesDescendants(parentState, childState)
The browser plugin adds the following to your router instance:
Build an URL
router.buildUrl(routeName, routeParams)
Match an URL
router.matchUrl(url)
Replace state in history and silently update your router instance state. Use if you know what you are doing.
router.replaceHistoryState(name, params)
Last modified 5yr ago