✌️
This commit is contained in:
parent
201f48d7e4
commit
6cd3c3e9ec
3 changed files with 44 additions and 53 deletions
42
src/web/app/dev/router.js
Normal file
42
src/web/app/dev/router.js
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
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();
|
||||
};
|
||||
|
||||
const riot = require('riot');
|
||||
function mount(content) {
|
||||
if (page) page.unmount();
|
||||
const body = document.getElementById('app');
|
||||
page = riot.mount(body.appendChild(content))[0];
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue