@librark/routark
v0.7.2
Published
Single Page Application Router
Downloads
9
Readme
Installation
Install Routark using npm
:
npm install @librark/routark
Getting Started
Routark is a client-side router designed to be incorporated in single page applications (SPAs), especially those using Web Component.
To use it in your application, you first need to create a Routark instance, and then add the routes you are willing to react to when visited:
import { Routark } from '@librark/routark'
const router = new Routark()
const prefix = '/'
router.addRoutes(prefix, [
{
path: 'about',
action: async () => {
document.body.innerHTML = '</h1>About Page</h1>'
}
},
{
path: 'home',
action: async () => {
document.body.innerHTML = '</h1>Home Page</h1>'
}
}
])
With the previous configuration, Routark will automatically react to several browser events (e.g. popstate), invoking the provided action callbacks when their corresponding routes get loaded.
Why Routark?
Routark is a simple and versatile client-side router with zero dependencies. It is framework agnostic and limits itself to provide a friction-less mechanism for invoking asynchronous action handlers when a certain route is loaded on the browser. So, if you are manipulating the DOM directly through Vanilla Javascript (e.g. using custom elements), you might find out that Routark is all you need for your client-side navigation!