You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
cyclic-router is a Router Driver built for Cycle.js
3
3
4
+
**Disclaimer** v2.x.x is for Cycle Diversity!
5
+
If you are still using @cycle/core please continue to use v1.x.x
6
+
4
7
## Installation
5
8
6
9
Using [npm](https://www.npmjs.com/):
@@ -21,170 +24,37 @@ var makeRouterDriver = require('cyclic-router').makeRouterDriver
21
24
22
25
For API documentation pleave visit this link [here](http://tylors.github.io/cyclic-router/docs/)
23
26
24
-
## Example
25
-
26
-
The example found in the repo can be taken for a test-drive [here](http://tylors.github.io/cyclic-router/example)
27
-
28
-
## Getting started
29
-
30
-
###1.
31
-
32
-
Here is a rundown of the `example` provided with this repo in the folder `/example`. This should allow a better understanding of how to use cyclic-router, for simplicity the styling has been removed here.
33
-
34
-
Starting in the file which has Cycle `run`, router driver needs to be created here along with the other drivers that you might be using.
35
-
36
-
```js
37
-
// main.js
38
-
import {run} from'@cycle/core'
39
-
import {makeDOMDriver} from'cycle-snabbdom'
40
-
import {makeRouterDriver} from'cyclic-router'
41
-
import {createHashHistory} from'history'
42
-
43
-
importappfrom'./app'// the function of your app
44
-
45
-
run(app, {
46
-
DOM:makeDOMDriver('#app'),
47
-
// Notice how you need to feed in funcs from cyclic-history + history
48
-
router:makeRouterDriver(createHashHistory()),
49
-
})
50
-
```
51
-
52
-
###2.
53
-
54
-
App.js will be used as the place for showing the correct component in reference to current url (what you'd expect from a router!).
55
-
When creating your `routes` object keep in mind that cyclic-router uses [switch-path](https://github.com/staltz/switch-path) and it is worth checking out that repo to understand the structure that `switch-path` expects.
27
+
## Basic Usage
56
28
57
29
```js
58
-
// app.js
59
-
import {div, nav} from'cycle-snabbdom'
60
-
61
-
importSidebarfrom'./components/sidebar'
62
-
importHomefrom'./components/home'
63
-
importInboxfrom'./components/inbox'
64
-
importComposefrom'./components/compose'
65
-
importNotFoundfrom'./components/notfound'
66
-
67
-
// routes is used for matching a route to a component
68
-
constroutes= {
69
-
'/': Home,
70
-
'/inbox': Inbox,
71
-
'/compose': Compose,
72
-
'*': NotFound,
73
-
}
74
-
75
-
// the view has sidebar & children passed in
76
-
functionview(sidebar, children) {
77
-
returndiv([
78
-
nav([sidebar]),
79
-
div([children]),
80
-
])
81
-
}
82
-
83
-
functionApp(sources) {
84
-
const {router} = sources // get router out of sources
85
-
constmatch$=router.define(routes) // pass routes into the router
86
-
constsidebar=Sidebar(sources, match$.pluck('path')) // pass in sources and path$ into our sidebar
87
-
88
-
// childrenDOM$ takes path$ from `router.define(routes)` above and zips it with values, here is where
89
-
// the components swap in reference to the current url, notice router.path(path) is also passed in
90
-
// for later use in nested routes.
91
-
// This allows components to be nested without ever knowing they are actually nested.
At this point you are at a good stage to be able to make a simple app/site with multiple pages. Next taking a look at nesting these routes directly within children components.
139
-
140
-
141
-
###4.
142
-
143
-
Nested routing becomes very trivial, as you can see below it is as simple as repeating the same steps as above.
0 commit comments