3.1.0 • Published 6 years ago

router5-link-interceptor v3.1.0

Weekly downloads
147
License
MIT
Repository
github
Last release
6 years ago

router5 link interceptor

Link interceptor plugin for router5.

Install

npm install --save router5-link-interceptor

API

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.

Arguments
  1. opts (Object or Function): The opts argument of Router5 navigate method. If you pass a Function, it will be called with fn(routeName, routeParams).
  2. [callback] (Function): The callback argument of Router5 navigate method.
Start and stop

The plugin only intercepts links when your router instance is started.

Usage

Basic

var linkInterceptor = require('router5-link-interceptor');
var router = getRouter5InstanceSomehow();

function callback(err) {
  if (err) console.error(err);
}

router.usePlugin(linkInterceptor({}, callback));

With opts object

var linkInterceptor = require('router5-link-interceptor');
var router = getRouter5InstanceSomehow();

function callback(err) {
  if (err) console.error(err);
}

router.usePlugin(linkInterceptor({reload: true}, callback));

With opts function

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));

Changelog

  • 3.0.0 - Make the link interceptor as a router5 plugin(d380fb2, #1).

License

The MIT License.

3.1.0

6 years ago

3.0.0

9 years ago

2.0.2

9 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.0.0

9 years ago