routal
v1.0.1
Published
A simple, light, modern, universal JavaScript router
Downloads
8
Maintainers
Readme
Usage
Hot to include?
import { Routal } from https://unpkg.com/[email protected]/routal.js
OR
npm i routal
How to Initialize?
let config = [
{pattern:'home',transition:'slide',axis:'y',component:(param)=>{return html`<the-home .param=${param}></the-home>`}},
{pattern:'user/:id',transition:'slide',duration:0.2,component:(param)=>{return html`<the-user .param=${param}></the-user>`} },
{pattern:'404',transition:'flip',component:(param)=>{return html` Nothing Here to show`} },
{pattern:'settings/*',transition:'flip',component:()=>{return html`<the-settings></the-settings>`}},
]
this.routal = new Routal(config,(routeComponent)=>{
console.log('callback received')
this.routeComponent = routeComponent
},'#container')
//cotainer could be a query pattern like #id of an element itself like this.querySelector('#id')
//Routal(config,callback,container) container is optional, It's default value is document.body
What to do with links?
// for lit-element
<a @click=${this.routal.link} href="/user/punyBot">punyBot </a>
//for vanilla js
<a onclick='routal.link()' href="/user/punyBot">punyBot</a>