summaryrefslogtreecommitdiff
path: root/src/web/app/ch/router.js
blob: 424158f403b8a3a7f483c9c89ca8797e25107eb3 (plain)
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
import * as riot from 'riot';
const route = require('page');
let page = null;

export default me => {
	route('/',         index);
	route('/:channel', channel);
	route('*',         notFound);

	function index() {
		mount(document.createElement('mk-index'));
	}

	function channel(ctx) {
		const el = document.createElement('mk-channel');
		el.setAttribute('id', ctx.params.channel);
		mount(el);
	}

	function notFound() {
		mount(document.createElement('mk-not-found'));
	}

	// EXEC
	route();
};

function mount(content) {
	if (page) page.unmount();
	const body = document.getElementById('app');
	page = riot.mount(body.appendChild(content))[0];
}