cycle-routing-driver
Routing driver for CycleJS that enables simple client-side routing.
npm install --save cycle-routing-driver
Usage
Updating the location bar and clicking links already works, so most of the work is hands-off. If you do need
to force a route change based on an event, just stream it in via the sinks.
import {run} from '@cycle/run'
import makeRoutingDriver, {routes} from 'lib/cyclejs/routing-driver'
function main(sources) {
const modal_ = sources.route.map(({query}) => query.modal)
return {
route: xs.merge(
sources.route.filter(({page}) => page === `404`).mapTo({page: `homepage`}),
sources.DOM.select(`.signup-modal`).events(`click`).mapTo({query: {modal: `signup`}}),
sources.DOM.select(`.modal-close`).events(`click`).mapTo({query: {modal: null}}),
),
}
}
run(main, {
route: makeRoutingDriver(
routes`
homepage
about
post (/posts/:post) -> view
view
edit
performance -> dashboard
demographics
reach
dashboard
search-ranking
`,
{
params: {
post: {
toData: _ => _,
toParam: data => data.id || data,
},
},
}
)
})