mercury-router

1.4.0 • Public • Published

Mercury RouterComponent

This is a mercury router component from Raynos : https://gist.github.com/adbf7951bee3fdfe1a65

Mercury is a FRP JS framework based on the idea of tiny modules: https://github.com/Raynos/mercury

Build Status

Install

npm install mercury-router

API

Mecury Router looks for two state attributes:

  • base: This attribute defines the base route of the router
  • route: This attribute defines the current/default route

Usage

  var mercury = require('mercury');
  var h = require('mercury').h;
  var anchor = require('mercury-router/anchor');
  var routeView = require('mercury-router/route-view');
  var Router = require('mercury-router');
 
  function App() {
    var state = mercury.struct({
      route: Router()
    });
 
    return state;
  }
 
  mercury.app(document.body, App(), render);
 
  function render(state) {
    return h('div', [
      menu(),
      routeView({
        '/': renderHome,
        '/animals': renderAnimals,
        '/animals/:id': renderAnimalItem
      }, { route: state.route })
    ])
  }
 
  function menu() {
    return h('ul', [
      h('li', [
        anchor({
          href: '/'
        }, 'Home')
      ]),
      h('li', [
        anchor({
          href: '/animals'
        }, 'Animals')
      ])
    ])
  }

Credits

Created By @Raynos Tests By @nikuda

LICENSE

see LICENSE

Readme

Keywords

Package Sidebar

Install

npm i mercury-router

Weekly Downloads

1

Version

1.4.0

License

MIT

Last publish

Collaborators

  • jrs
  • twilson63
  • matthewp