Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.
/ yagni-router Public archive

You ain't gonna need it (router for browser apps)

License

Notifications You must be signed in to change notification settings

yagni-js/yagni-router

Repository files navigation

yagni-router

Yet another pure functional router for browser.

Pure functional in this context means functional code style - library code is linted using eslint-plugin-fp and eslint-plugin-better. Javascript code of the library is purely functional.

Source code is written using ES6 modules, built using rollup and distributed in two formats - as CommonJS module and as ES6 module.

Features

Currently supports hash-based routing only.

Installation

Using npm:

$ npm install --save-dev @yagni-js/yagni @yagni-js/yagni-dom @yagni-js/yagni-router

Using yarn:

$ yarn add -D @yagni-js/yagni @yagni-js/yagni-dom @yagni-js/yagni-router

Usage

CommonJS usage:

const url = require('@yagni-js/yagni-router').url;
const hashRouter = require('@yagni-js/yagni-router').hashRouter;

ES6 module usage:

import { url, hashRouter } from '@yagni-js/yagni-parser';

Documentation

Not yet available, please check sources.

Example

import { url, hashRouter } from '@yagni-js/yagni-parser';


function fooHandler(match) {
    // ...
}

function bazHandler(match) {
    // ...
}

const routes = [
  url(/^foo/, fooHandler),
  url(/^baz\/\d+$/, bazHandler)
];

const router = hashRouter(routes);

window.addEventListener('hashchange', router, false);

License

Unlicense