2.0.4 • Published 2 years ago

spath v2.0.4

Weekly downloads
76
License
MIT
Repository
github
Last release
2 years ago

Spath

Capture anchor clicks and do a pushState instead of navigating

Example

Demo app

Why

Most SPA's need to capture default anchor behaviour and do a pushState, this module encaptulates that logic.

Getting started

npm i --save spath

Exposes individually or wrapped

const pushStateAnchors = require('spath/pushStateAnchors')
const setPath = require('spath/setPath')

/* Capture all anchor clicks and instead to a pushState */
document.addEventListener('click', pushStateAnchors())

/* Custom capture logic */
document.addEventListener('click', pushStateAnchors(href => {
  return href.startsWith(window.location.origin)
}))

/* To programmatically pushState */
setPath('/some-path')

Detecting path change

on-url-change can be used to detect when the page's URL has changed.

Developing

git clone git@github.com:markwylde/spath.git
cd spath
npm install
npm run start

Then goto: http://localhost:8080

License

This project is licensed under the terms of the MIT license.

2.0.4

2 years ago

2.0.3

3 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.4.0

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.1

5 years ago

1.0.0

5 years ago