vanillajs-router
v1.1.0
Published
A simple-to-use VanillaJS SPA cross-browser router
Downloads
5
Readme
vanilla-spa-router
Simple-to-use VanillaJS (SPA) Router
Probably you even no need to use this but it's ok :)
Advantages:
- NO dependencies
- NO conflicts
- NO overrides
- just include as source or module
- IE6+, Firefox 2+
Installation
... as source <script src="router.js"></script>
... as module yarn add vanilla-spa-router
API
Use window._Router(ops)
or new Router(ops)
to access to routing
Available options
mode: 'history'(default) or 'hash'
Choose the way of routingbase: '/'(default)
Set base directory
Methods
.init(ops)
Rebind your options accordingly.start()
Start working with router using History API or#anchor
.use(String route, Function middleware)
Subscribe for router updates for exact path with needed paramsmiddleware(Object data)
- Receives transformed data from path name. You can continue working straight with Router usingthis
inside middleware.navigate(String path)
Replaces you to the needed location