DEV Community

Discussion on: Build a very basic SPA JavaScript router

Collapse
 
akhilarjun profile image
Akhil Arjun

Thats a neat implementation.

I once meddled with the same idea and built a small. Router called RouteNow.

It started with a simple hashbang routing as you did here, and then shifted default routing method to history.pushState and popState. As that forms better readable urls.

GitHub logo akhilarjun / RouteNow

RouteNow is a small fast library ⚡ that will help you in developing a SinglePage Application without any dependencies like jQuery, AngularJs, vue.js or any of those bulky frameworks.

RouteNow

Contributions-Welcome experimental File-Size Version

A new revolutionary small router with no bullshit!

RouteNow is a small library that will help you in developing a SinglePage Application without any dependencies like jQuery, AngularJs, vue.js or any of those bulky frameworks.

Installation

Installating RouteNow.js is as easy as it gets.

Add the script to the end of your body

<script src="../pathto/route-now.js"></script>

Or use the CDN link


<script src="https://cdn.jsdelivr.net/gh/akhilarjun/RouteNow@latest/js/route-now.js"></script>
<!-- For specific version use the version tag -->
<script src="https://cdn.jsdelivr.net/gh/akhilarjun/RouteNow@v2.0.1/js/route-now.js"></script>
<!-- For Minified -->
<script src="https://cdn.jsdelivr.net/gh/akhilarjun/RouteNow@v2.0.1/js/route-now.min.js"></script>

Use anchor tags with r-href property to point to your paths

<a r-href="home">Home</a>

Now add the Router outlet where the views should…

Collapse
 
labzdjee profile image
Gérard Gauthier

Thank you for the information. Seems you haven't published this as an NPM package. That's a must nowadays, should we want to include your work in a Webpack managed project.