Vanilla UI Router
Simple vanilla JavaScript router to be used inside a single page app to add routing capabilities.
The router comes with zero dependencies and can be used with any other libraries. It's based on the hashchange-Event.
Installation
$ npm install --save vanilla-ui-router
As UMD module this runs everywhere (ES6 modules, CommonJS, AMD and with good ol’ globals).
Usage
Let's assume your initial markup has the following structure:
<!-- Entry point, dynamic content is rendered into this DOM element --> <!-- Bundle where your JavaScript logic lives, even the router configuration -->
Then you could configure the router with the following JavaScript:
; // Initialize the router with the dynamic DOM entry pointconst router = ; router // Start route: The server side URL without a hash /* If routes get more complex, e.g. you need to render a template URL, pass a configuration object as second parameter (instead of the function) */ /* You can also define a templateId, i.e. if you have a template-script inside your markup like: <script type="text/template" id="template42"> <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolor, tenetur? </p> </script> */ // if you need to pass custom data to your routes ;
License
Please be aware of the licenses of the components we use in this project. Everything else that has been developed by the contributions to this project is under MIT License.