Skip to content

mynameistechno/mercury-router

 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 99.9%
  • HTML 0.1%