markojs-router
v1.0.0
Published
Client-Side Routing for MarkoJS
Downloads
5
Readme
markojs-router
$ npm install markojs-router
import { Router } from 'markojs-router';
// Create Router
var router = new Router(document.getElementById('app'));
// Add Routes
router.add({
name: 'Home',
path: '/',
component: require('./app/views/index.marko')
});
router.add({
name: 'About',
path: '/about',
component: require('./app/views/about.marko')
});
router.add({
name: 'Contact',
path: '/contact',
component: require('./app/views/contact.marko')
});
/////////////////////////////////////////////////////////////////////
// Attach buttons manually
var activeRoutes = Array.from(document.querySelectorAll('[route]'));
activeRoutes.forEach(function (route) {
route.addEventListener('click', function (event) {
router.eventHandler(event)
}, false);
});
/////////////////////////////////////////////////////////////////////
// Render View
router.render();