This is a mercury router component from Raynos : https://gist.github.com/adbf7951bee3fdfe1a65
Mercury is a FRP JS framework based on the idea of tiny modules: https://github.com/Raynos/mercury
npm install mercury-router
Mecury Router looks for two state attributes:
- base: This attribute defines the base route of the router
- route: This attribute defines the current/default route
var mercury = require('mercury');
var h = require('mercury').h;
var anchor = require('mercury-router/anchor');
var routeView = require('mercury-router/route-view');
var Router = require('mercury-router');
function App() {
var state = mercury.struct({
route: Router()
});
return state;
}
mercury.app(document.body, App(), render);
function render(state) {
return h('div', [
menu(),
routeView({
'/': renderHome,
'/animals': renderAnimals,
'/animals/:id': renderAnimalItem
}, { route: state.route })
])
}
function menu() {
return h('ul', [
h('li', [
anchor({
href: '/'
}, 'Home')
]),
h('li', [
anchor({
href: '/animals'
}, 'Animals')
])
])
}
Created By @Raynos Tests By @nikuda
see LICENSE