Router Web Component
A small, declarative router web component for single-page apps that allows you to load pages dynamically when urls are requested without performing a hard reload of the entire web page.
Benefits
- Very lightweight and no dependencies -- only provides routing needs and nothing more
- Declaritive syntax, no configuration file needed
- Automatically intercepts all
<a>
tags on a page (that contain relativehref
s) to prevent them from causing page reloads, which use pushState() API.
Examples
Samples of how to use this package can be found in the examples folder.
Installation
npm i router-js
Prerequisites
This library assumes you are using a browser that supports Web Components. They are the future of the web and are already implemented natively in browsers. So if you aren't already using them, you probably should.
Before using this package, make sure your server is setup to have all your page URIs to point to the root index.html page of your single-page application, which will have your router code. An example of the index.html is below.
Usage
Basic Example
Advanced Example
Development
To run tests:
npm test