zliq-router

0.0.2 • Public • Published

ZLIQ-Router

ZLIQ

Router for the light zliq-framework.

Quickstart

To use ZLIQ in your project, first install it as an dependency:

$ npm install --save zliq zliq-router

Then initialize the router which hooks into document events

import {h} from 'zliq';
import {initRouter} from 'zliq-router';
 
let router$ = initRouter()
 
let app = <div>
        <a href="/route?param=value#anchor" />
    </div>;
document.querySelector('#app').appendChild(app);
 
// Will be '/route {param: 'value'} anchor after click on link
router$.map(({route, params, anchor}) => console.log(route, params, anchor))
 

To route you could switch on route values.

let router$ = initRouter()
 
let app = <div>
        <a href="/route?param=value#anchor" />
        {
            if$(router$.$('route').is('route'),
                <h1>Subpage</h1>,
                <h1>Titel</h1>)
         )
        }
    </div>;
document.querySelector('#app').appendChild(app);

Or you use the Router component. The component also registers its route so we can fallback to '/' on missing route. We can also add a '/404' route that gets triggered on a missing route if available.

let router$ = initRouter()
 
let app = <div>
        <a href="/route?param=value#anchor" />
        <Router router$={router$} route='/'>
            <h1>Titel</h1>
        </Router>
        <Router router$={router$} route='/route'>
            <h1>Subpage</h1>
        </Router>
    </div>;
document.querySelector('#app').appendChild(app);

Logo based on: http://www.iconsfind.com/2015/11/25/candy-dessert-food-sweet-baby-icon/

Readme

Keywords

none

Package Sidebar

Install

npm i zliq-router

Weekly Downloads

3

Version

0.0.2

License

MIT

Last publish

Collaborators

  • faboweb