0.0.5 • Published 2 years ago

tool-shop-js-router v0.0.5

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

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