Skip to content

Latest commit

 

History

History
60 lines (41 loc) · 1.28 KB

readme.md

File metadata and controls

60 lines (41 loc) · 1.28 KB

Radar

A window history no config router.

npm NPM GitHub last commit

Install

npm install @devinle/radar

// In your script
import { radar } from '@devinle/radar';

// Make a callback function
const callback = (data) => { console.log(data); };

// Data Signature within callback is as follows
data = {
  from: 'from/page/url,
  to: 'to/page/url'
};

// Register a callback with the radar-change event
// This event will receive data
radar.on('radar-change', callback);

// Remove a specific callback from the radar-change
radar.off('radar-change', callback);

Usage

All links delegate to the body and will make a request to the window pushState.

<a href="/url/here">A Link</a>

Prevent History Request

To avoid calling the window pushState function, apply the radar-ignore class to a link.

<a href="/url/here" class="radar-ignore">A Link</a>

Method radar.go(evt)

The body is bound to the radar.go method and all links clicked within the body will call this API method unless it contains the ignore class.

Tests

yarn run test

License

MIT