Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

cycle-router is a driver for Cycle.js that allows to add multiple views and handle routing.

License

NotificationsYou must be signed in to change notification settings

hollwann/cycle-router

Repository files navigation

Build Status

cycle-router is a driver for Cycle.js that allows to add multiple views and handle routing.

  • Navigate with path or name
  • BeforeEach hook
  • Hash mode

Installation

$ npm install @hollwann/cycle-router

Usage

The usage is as simple as any other driver, here is an example of the main function using cycle-router.

import{makeDOMDriver}from'@cycle/dom'importmakeRouterDriverfrom'@hollwann/cycle-router'importrouterConfigfrom'./routerConfig'importrunfrom'@cycle/run'constmain=(sources)=>{constrouterView=sources.router.currentView(sources)constsinks={DOM:routerView.select('DOM'),router:routerView.select('router')}returnsinks}constdrivers={DOM:makeDOMDriver('#app'),router:makeRouterDriver(routerConfig)}run(main,drivers)

You pass all the sources to your view and then you get the sinks returned. WithrouterView.select you can get any sink you get from that view.

You must specify a configuration file which should look like this.

importHomefrom'./views/Home'importLoginfrom'./views/Login'constroutes=[{path:'/',name:'home',view:Home,meta:{/*meta prop is optional*/requiresAuth:true}},{path:'/login',name:'login',view:Login}]constbeforeEach=(routeTo)=>{//This is just an exampleconstcurrentUser='user'//some valid user hereconstauthRequired=routeTo.meta.authRequiredif(authRequired&&currentUser)return{name:RouteTo.name}elseif(authRequired&&!currentUser)return{name:'login'}return{name:routeTo.name}}exportdefault{ routes,defaultView:Home,/*optional*/ beforeEach}

beforeEach is an optional function, which is executed before entering a new route.

You can navigate passing a stream of objects to the router sink, whit the name of the route or ther path. A simple example could be:xs.of({name:'home'})

License

MIT

Copyright (c) 2020, Hollwann

About

cycle-router is a driver for Cycle.js that allows to add multiple views and handle routing.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp