1.4.0 • Published 9 years ago

mercury-router v1.4.0

Weekly downloads
8
License
MIT
Repository
github
Last release
9 years ago

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

1.4.0

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago

1.1.0

10 years ago

1.0.9

10 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.0

11 years ago