tool-shop-js-router

0.0.5 • Public • Published

Tool Shop JS Router

This JavaScript library provides an easy to use router for your web application. It's based on Navigo and works best in combination with the Tool Shop JS Widgets.

Tests NPM Size


Get Started

Installation:

Install with NPM using your CLI:

npm install --save tool-shop-js-router

Usage

Example for the usage of the Router:

// Router returns an instance of the Navigo Router
const router = Router({
    hooks: {
        before(done) {
            // ... do something before each page is rendered
            done();
        }
    },
    routes: {
        "/about": {
            page: AboutPage,
            // layout is optional. If not set, 
            // the page is rendered to the body tag directly.
            layout: DefaultLayout 
        },
        // default page
        "*": { 
            page: HomePage,
            layout: DefaultLayout
        }
    }
});

API

Page Element

The router instance has a property holding the current page HTML element.

const router = Router(/* ... */);
router.pageElement; // the pages HTML element currently rendered

TODO

  • [ ] Pass URL and query params to the page constructor

Package Sidebar

Install

npm i tool-shop-js-router

Weekly Downloads

2

Version

0.0.5

License

Apache-2.0

Unpacked Size

10 kB

Total Files

8

Last publish

Collaborators

  • dobschal