Last active
January 14, 2017 01:40
-
-
Save ishiduca/d63af6d55ab9acad43f414ecd719e60d to your computer and use it in GitHub Desktop.
example of sheet-router with yo-yo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sheetRouter = require('sheet-router') | |
const href = require('sheet-router/href') | |
const html = require('yo-yo') | |
const d = require('global/document') | |
const mainView = params => html ` | |
<div style="display:flex;flex-direction:row"> | |
<div><a href="/Twiggy/orgs">gotcha Twiggy !</a></div> | |
<div><a href="/ishiduca" data-no-routing>gotcha ishiduca !</a></div> | |
</div> | |
` | |
const userViewIn = params => `<h1>${params.username}</h1>` | |
const userView = (params, h1) => html `<div>${(h1 || userViewIn)(params)}</div>` | |
const router = sheetRouter({default: '/404'}, [ | |
['/', mainView], | |
['/:username', params => userView(params), | |
['/orgs', params => userView(params, p => html `<h1>${p.username} org!</h1>`)] | |
], | |
['/404', params => html `<div>oh no, path to not found</div>`] | |
]) | |
href(h => { | |
html.update(root, router(h.pathname)) | |
console.log(`link was clicked "${h.pathname}"`) | |
}) | |
const root = router('/') | |
d.body.appendChild(root) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment