@devinle/radar

A router.

Usage no npm install needed!

<script type="module">
  import devinleRadar from 'https://cdn.skypack.dev/@devinle/radar';
</script>

README

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