Skip to content

Latest commit

 

History

History
54 lines (42 loc) · 1.78 KB

README.md

File metadata and controls

54 lines (42 loc) · 1.78 KB

catch links

tests Socket Badge types module dependencies semantic versioning license

Like the classic @substack module, but updated.

Intercept local link clicks on a page, for client-side pushState UIs.

This is used as a part of route-event. That is the recommended way to consume this.

install

npm i -S @bicycle-codes/catch-links

use

common JS

const catchLinks = require('@bicycle-codes/catch-links').default

ESM

import CatchLinks from '@bicycle-codes/catch-links'

example

Given this HTML,

<body>
    <a id="local-link" href="/foo">local</a>
    <a href="https://www.npmjs.com/" id="remote-link">remote</a>
</body>

Use this JS:

import CatchLinks from '@bicycle-codes/catch-links'

// given a click on `#local-link`
CatchLinks(document.body, function onLinkClick (href) {
    // this will not be called on click to #remote-link

    console.log('href', href)
    // => '/foo'
})