Migrating from 1.x to 2.x
- You can now pass to
router.add()
objects containingcanActivate
functions and those functions will be registered. No need to call for each routeaddNode
orcanActivate
. - Persistent parameters plugin now available.
router.registerComponent
androuter.deregisterComponent
have been removed in favour ofcanDeactivate
- Additional arguments now apply to middleware functions.
- Context has been removed from middleware functions.
- Middleware functions are now a function taking a router instance and returning a function called on each transition.
- Plugins, like middleware functions, are now a function taking a router instance and returning an object of methods (which doesn't contain an
init
function anymore). autoCleanUp
is no longer shared with router5-listeners. If you need to turn off automatic deregistration of node listeners, pass{ autoCleanUp: false }
to the listeners plugin.router5
package now exportsRouter5
as default, andRouteNode
,loggerPlugin
,errCodes
andtransitionPath
as named exports
ES2015+
import Router5, { loggerPlugin } from 'router5';
import historyPlugin from 'router5-history';
import listenersPlugin from 'router5-listeners';
const router = new Router5()
.add([{
name: 'home',
path: '/home'
}])
.usePlugin(historyPlugin())
.usePlugin(listenersPlugin())
// Development helper
.usePlugin(loggerPlugin())
.start();
ES5
var router5 = require('router5');
var Router5 = router5.default;
var loggerPlugin = router5.loggerPlugin;
var historyPlugin = require('router5-history');
var listenersPlugin = require('router5-listeners');
var router = new Router5()
.add([{
name: 'home',
path: '/home'
}])
.usePlugin(historyPlugin())
.usePlugin(listenersPlugin())
// Development helper
.usePlugin(loggerPlugin())
.start();
Last modified 5yr ago