routal

1.0.1 • Public • Published

Routal

A simple, universal, light, modern Router with animation skills that supports pushState (update pages without reloading) and keep links SEO friendly


  • Tested well with lit-element (check out the demo code @ index.js & index.html)
  • Tested well with vanilla JS

Usage

Hot to include?

import { Routal } from https://unpkg.com/routal@1.0.0/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>

Package Sidebar

Install

npm i routal

Weekly Downloads

3

Version

1.0.1

License

MIT

Unpacked Size

15.5 kB

Total Files

5

Last publish

Collaborators

  • itsarnavsingh