cycle-routing-driver
Advanced tools
Comparing version 0.1.2 to 0.1.3
{ | ||
"name": "cycle-routing-driver", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "A bare-bones router for simple frontend routing in CycleJS", | ||
@@ -5,0 +5,0 @@ "main": "dist/routing-driver.js", |
@@ -6,4 +6,23 @@ cycle-routing-driver | ||
Routing driver for [CycleJS](https://cycle.js.org/) that enables simple client-side routing. | ||
Routing driver for [CycleJS](https://cycle.js.org/) that enables simple client-side routing, without worrying about | ||
the frills that more complex routers bring. | ||
## Intention | ||
This library considers data-loading and rendering outside of its scope - this is all about converting back and forth | ||
between `window.location` and a route object, with some extra goodness to make it fun to use. | ||
A route object is a simple bundle of three properties - `page`, `data`, and `query`. Every route has a name which is set | ||
in the `page` property, and is generated according to the configuration used when creating the router. When there are url | ||
parameters in the configuration, those values are mapped into the `data` property. And finally, any query string info is | ||
mapped into the `query` property. | ||
In addition to the properties mentioned above, a route object also has a function called `toUrl`. This function can be | ||
called with a "route-like" argument to generate the URL for another route, while preserving the rest of the current routes | ||
details. For example, `postViewRoute.toUrl({page: "post.edit"})` would preserve the data for the post being viewed, (eg. the | ||
post id parameter in the URL) but change the path to match the post edit route. This is useful when generating links in | ||
markup which relate to the current route. | ||
## Usage | ||
```js | ||
@@ -13,4 +32,2 @@ 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 | ||
@@ -42,11 +59,22 @@ to force a route change based on an event, just stream it in via the sinks. | ||
/* | ||
* the configuration below supports the following route structure: | ||
* /homepage | ||
* /about | ||
* /post/:post | ||
* /post/:post/edit | ||
* /post/:post/performance (this will auto-redirect to /post/:post/performance/dashboard) | ||
* /post/:post/performance/demographics | ||
* /post/:post/performance/reach | ||
* /post/:post/performance/dashboard | ||
* /post/:post/performance/search-ranking | ||
*/ | ||
run(main, { | ||
// other stuff..., | ||
route: makeRoutingDriver( | ||
// the routes DSL provides a clean interface for defining basic routes | ||
// the `routes` DSL provides a clean interface for defining basic routes | ||
routes` | ||
homepage | ||
about | ||
post (/posts/:post) -> view | ||
view | ||
post (/posts/:post) | ||
edit | ||
@@ -69,3 +97,2 @@ performance -> dashboard | ||
}) | ||
``` |
14883
95