This module is mainly to intercept applicable link clicks for a single-page app router. The options are geared toward intercepting internal links that should change the page state in some way.
$ npm install --save intercept-link-clicks
const interceptClicks = require('intercept-link-clicks')
interceptClicks((e, el) => {
// Change the page state here
// `e` is the event object
// `el` is the clicked link, which might be different from `e.target`
});
A more advanced usage is to pass options and an optional element:
interceptClicks(document.querySelector('.my-el'), {
//
// Leave all these as defauts:
//
// modifierKeys: true
// download: true
// target: true
// hash: true
// mailTo: true
// Support events crossing a shadow dom boundry,
// required for capturing link clicks inside web components
// shadowDom: true
// Intercept all clicks, even ones that are not same origin
sameOrigin: false
}, (e, el) => {
// Change the page state here
});