Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pygy/morgul-road
The mitrhril router pared down for standalone use.
https://github.com/pygy/morgul-road
Last synced: 25 days ago
JSON representation
The mitrhril router pared down for standalone use.
- Host: GitHub
- URL: https://github.com/pygy/morgul-road
- Owner: pygy
- Created: 2016-03-06T00:35:44.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-03-06T18:46:03.000Z (over 8 years ago)
- Last Synced: 2024-04-13T19:23:35.847Z (7 months ago)
- Language: JavaScript
- Size: 42 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# morgul-road
The mithril router extracted for standalone use.
**CAVEAT: This adaptation hasn't been tested at all (I didn't even try to run it). It may very well be broken (or just work as advertised, who knows).**
## Installation:
```bash
$ npm install morgul-road
```## Usage:
```JS
import makeRouter from 'morgul-road'; // also works with `require('morgul-road')`// a basic router that swaps DOM nodes
const route = makeRouter(function updater(root, node) {
// remove this if you don't want the page to scroll up on route change
if (updater.preRedraw) updater.preRedraw();if(root.firstChild) {
root.replaceChild(node, root.firstChild);
} else {
root.appendChild(node);
}// this is mandatory to push or replace the history state.
if (updater.postRedraw) updater.postRedraw();})
main = document.createElement('h1')
main.innerHTML = 'Hello'route(document.body, '/', {
'/' : main //, ...
})
```The `route` function has the same (polymorphic) signature as [m.route](http://mithril.js.org/mithril.route.html).