Skip to content

lius/cyclic-router

 
 

Repository files navigation

cyclic-router

cyclic-router is a Router Driver built for Cycle.js

Disclaimer v2.x.x is for Cycle Diversity! If you are still using @cycle/core please continue to use v1.x.x

Installation

Using npm:

$ npm install cyclic-router

Then with a module bundler like browserify, use as you would anything else:

// using an ES6 transpiler, like babel
import {makeRouterDriver} from 'cyclic-router'

// not using an ES6 transpiler
var makeRouterDriver = require('cyclic-router').makeRouterDriver

API

For API documentation pleave visit this link here

Basic Usage

import xs from 'xstream';
import Cycle from '@cycle/xstream-run';
import {makeDOMDriver} from '@cycle/dom';
import {makeRouterDriver} from 'cyclic-router';
import {createHistory} from 'history';

function main(sources) {
  const match$ = sources.router.define({
    '/': HomeComponent,
    '/other': OtherComponent
  });
  
  const page$ = match$.map(({path, value}) => {
    return value(Object.assign({}, sources, {
      router: sources.router.path(path);
    }));
  });
  
  return {
    DOM: page$.map(c => c.DOM).flatten(),
    router: xs.of('/other'),
  };
}

Cycle.run(main, {
  DOM: makeDOMDriver('#app'),
  router: makeRouterDriver(createHistory())
});

Route Parameters

You can pass route parameters to your component by adding them to the component sources.

const routes = {
  '/:id': id => sources => YourComponent({props$: Observable.of({id}), ...sources})
}

About

Router Driver built for Cycle.js

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 85.5%
  • TypeScript 14.5%