forked from twilson63/mercury-router
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (43 loc) · 1.08 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
var mercury = require('mercury');
var h = require('mercury').h;
var router = require('../');
var anchor = router.anchor;
function App() {
var state = mercury.state({
title: mercury.value('Router Example'),
route: router()
});
return state;
}
mercury.app(document.body, App(), render);
function render(state) {
return h('div', [
h('h1', [state.title]),
menu(),
router.render(state, {
'/': function routeHome() {
return h('h1', ['Home']);
},
'/animals': function routeAnimals() {
return h('h1', ['Animals']);
},
'/animals/:id': function routeAnimal(params) {
return h('h1', ['Animals ' + params.id]);
}
})
]);
}
function menu() {
return h('ul', [
h('li', [
anchor({ href: '/'}, 'Home')
]),
h('li', [
anchor({ href: '/animals' }, 'Animals')
]),
h('li', [
anchor({ href: '/animals/1'}, 'Animals1')
])
]);
}