domr-router
v1.0.2
Published
a Component Based JavaScript Micro-Framework equipped with a static Router
Downloads
2
Maintainers
Readme
DOMR Router
A static router for creating hash routes.
Install
Use npm or yarn to install domr-router
npm install domr-router --save
yarn add domr-router
Use Router
import { Router } from 'domr-router';
import HomePageView from './views/HomePageView';
import ConfigView from './views/ConfigView';
const router = new Router([
{
path: '/',
view: HomePageView,
isDefault: true,
},
{
path: '/config/',
view: ConfigView,
},
{
path: '/config/:topic',
view: ConfigView,
},
]);
router.Start();
Router supports wildcard entries like (*, :name)
Router class
Router() class takes array of routes as the first parameter. The routes object contains two main parameter and one optional isDefault parameter.
- path - hash url location
- view - a function to execute (without parentheses)
- isDefault (optional) - if set true then the route becomes the default path
.Start()
Initializes the router
Advanced Router class props
...
const router = new Router(routes, {
refreshPage: true,
});
...
Besides the first parameter i.e. the array of routes Router class also takes config obj as the second parameter.
- refreshPage - if set true then refresh the page on every hash change