API reference

Core

createRouter([routes], [options], [dependencies]) Create a router
Params
routes Array The routes
options Object={} The router options
dependencies Object={} The router dependencies
Return Object The router instance
router.makeState(name, params, path, [metaParams], [source]) Build a state object
Params
name String The state name
params Object The state params
path String The state path
metaParams Object Description of the state params
source String The source of the routing state
Return Object The state object
router.makeNotFoundState(path) Build a not found state for a given path
Params
path String The unmatched path
Return Object The not found state object
router.getState() Get the current router state
Return Object The current state
router.setState(state) Set the current router state
Params
state Object The state object
router.getOptions() Get router options
Return Object The router options
router.setOption(option, value) Set an option
Params
option String The option name
value * The option value
Return Object The router instance
router.setDependency(dependencyName, dependency) Set a router dependency
Params
dependencyName String The dependency name
dependency * The dependency
Return Object The router instance
router.setDependencies(deps) Add dependencies
Params
deps Object A object of dependencies (key-value pairs)
Return Object The router instance
router.getDependencies() Get dependencies
Return Object The dependencies
router.add(routes) Add routes
Params
routes Array A list of routes to add
Return Object The router instance
router.addNode(name, path, [canActivateHandler]) Add a single route (node)
Params
name String The route name (full name)
path String The route path (from parent)
canActivateHandler Function The canActivate handler for this node

Router lifecycle

router.isStarted() Check if the router is started
Return Boolean Whether the router is started or not
router.start(startPathOrState, done) Start the router
Params
startPathOrState StringObject The start path or state. This is optional when using the browser plugin.
done Function A done node style callback (err, state)
Return Object The router instance
router.stop() Stop the router
Return Object The router instance

Navigation

router.cancel() Cancel the current transition if there is one
Return Object The router instance
router.forward(fromRoute, toRoute) Forward a route to another route, when calling navigate. Route parameters for the two routes should match to avoid issues.
Params
fromRoute String The route name
toRoute String The route params
router.navigate(routeName, [routeParams], [options], [done]) Navigate to a route
Params
routeName String The route name
routeParams Object The route params
options Object The navigation options (`replace`, `reload`)
done Function A done node style callback (err, state)
Return Function A cancel function
router.navigateToDefault([opts], [done]) Navigate to the default route (if defined)
Params
opts Object The navigation options
done Function A done node style callback (err, state)
Return Function A cancel function

Route lifecycle

router.canDeactivate(name, canDeactivateHandler) Register a canDeactivate handler or specify a if a route can be deactivated
Params
name String The route name
canDeactivateHandler FunctionBoolean The canDeactivate handler or boolean
Return Object The router instance
router.clearCanDeactivate(name) Remove a canDeactivate handler for a route
Params
name String The route name
Return Object The router instance
router.canActivate(name, canActivateHandler) Register a canActivate handler or specify a if a route can be deactivated
Params
name String The route name
canActivateHandler FunctionBoolean The canActivate handler or boolean
Return Object The router instance

Middleware

router.useMiddleware(...middlewares) Register middleware functions.
Params
middlewares ...Function The middleware functions
Return Object The router instance
router.clearMiddleware() Remove all middleware functions
Return Object The router instance

Plugins

router.usePlugin(...plugins) Use plugins
Params
plugins ...Function An argument list of plugins
Return Object The router instance
router.hasPlugin(pluginName) Check if a plugin has already been registered.
Params
pluginName String The plugin name
Return Boolean Whether the plugin has been registered

Utils

router.isActive(name, params, [strictEquality], [ignoreQueryParams]) Check if a route is currently active
Params
name String The route name
params Object The route params
strictEquality Boolean=false Whether to check if the given route is the active route, or part of the active route
ignoreQueryParams Boolean=true Whether to ignore query parameters
Return Boolean Whether the given route is active
router.areStatesEqual(state1, state2, ignoreQueryParams) Compare two route state objects
Params
state1 Object The route state
state2 Object The other route state
ignoreQueryParams Boolean Whether to ignore query parameters or not
Return Boolean Whether the two route state are equal or not
router.areStatesDescendants(parentState, childState) Check if two states are related
Params
parentState State The parent state
childState State The child state
Return Boolean Whether the two states are descendants or not
router.buildPath(route, params) Build a path
Params
route String The route name
params Object The route params
Return String The path
router.matchPath(path, [source]) Match a path
Params
path String The path to match
source String The source (optional, used internally)
Return Object The matched state (null if unmatched)
router.setRootPath(rootPath) Set the root node path, use carefully. It can be used to set app-wide allowed query parameters.
Params
rootPath String The root node path

Clone

router.clone(deps) Clone the current router configuration. The new returned router will be non-started, with a null state
Params
deps [description]
Return [description]