Link interceptor plugin for router5.
npm install --save router5-link-interceptor
router.usePlugin(linkInterceptor(opts, [callback]));
Register a plugin to intercept all click events of links and call the Router5 navigate method. Query string of the link will be parsed into routeParams
.
opts
(Object or Function): Theopts
argument of Router5 navigate method. If you pass a Function, it will be called withfn(routeName, routeParams)
.[callback]
(Function): Thecallback
argument of Router5 navigate method.
The plugin only intercepts links when your router instance is started.
var linkInterceptor = require('router5-link-interceptor');
var router = getRouter5InstanceSomehow();
function callback(err) {
if (err) console.error(err);
}
router.usePlugin(linkInterceptor({}, callback));
var linkInterceptor = require('router5-link-interceptor');
var router = getRouter5InstanceSomehow();
function callback(err) {
if (err) console.error(err);
}
router.usePlugin(linkInterceptor({reload: true}, callback));
var linkInterceptor = require('router5-link-interceptor');
var router = getRouter5InstanceSomehow();
function opts(routeName, routeParams) {
if (routeName === 'home') {
return {reload: true};
}
return {};
}
function callback(err) {
if (err) console.error(err);
}
router.usePlugin(linkInterceptor(opts, callback));
The MIT License.