mercury-router
v1.4.0
Published
This is a mercury router component from Raynos : https://gist.github.com/adbf7951bee3fdfe1a65.git
Downloads
56
Readme
Mercury RouterComponent
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
Install
npm install mercury-router
API
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
Usage
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')
])
])
}
Credits
Created By @Raynos Tests By @nikuda
LICENSE
see LICENSE