egirlskey/src/web/app/dev/router.js

43 lines
846 B
JavaScript
Raw Normal View History

2017-02-18 09:03:52 +00:00
const route = require('page');
let page = null;
module.exports = me => {
route('/', index);
route('/apps', apps);
route('/app/new', newApp);
route('/app/:app', app);
route('*', notFound);
function index() {
mount(document.createElement('mk-index'));
}
function apps() {
mount(document.createElement('mk-apps-page'));
}
function newApp() {
mount(document.createElement('mk-new-app-page'));
}
function app(ctx) {
const el = document.createElement('mk-app-page');
el.setAttribute('app', ctx.params.app);
mount(el);
}
function notFound() {
mount(document.createElement('mk-not-found'));
}
// EXEC
route();
};
2017-03-18 11:05:11 +00:00
import * as riot from 'riot';
2017-02-18 09:03:52 +00:00
function mount(content) {
if (page) page.unmount();
const body = document.getElementById('app');
page = riot.mount(body.appendChild(content))[0];
}