1.0.0 • Published 5 years ago

markojs-router v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

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();