Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cycle-route

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cycle-route - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

2

package.json
{
"name": "cycle-route",
"version": "1.0.0",
"version": "1.0.1",
"description": "A Cycle.js helper for routing",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

# Cycle Route
A simple router factory that takes a static map of route => label and returns a function that maps a path to a route object of the form
A simple router factory that takes a static map of route => label and returns a function that maps a path to a route object.
```js
{
path: '/',
name: 'home',
params: {}
}
```
It was created to be used with [```cycle-pushstate-driver```](https://github.com/secobarbital/cycle-pushstate-driver) but is a generic URL mapper that can be as a helper in any routing engine.

@@ -18,5 +10,21 @@

```sh
npm install @cycle-route
npm install cycle-route
```
## API
###```makeRouter(routes)```
Takes as input a map from route definition to route name and returns a router function. ```cycle-route``` uses [```routington```](https://github.com/pillarjs/routington) so it accepts all route definitions that ```routington``` accepts and adds a ```*``` route to define the default route.
## Format of route object
```js
{
path: '/', // this is the input path
name: 'home', // this is the value from the routes map
params: {} // this are the matched params
}
```
## Usage

@@ -27,11 +35,11 @@

```js
import makeRouter from ‘cycle-route’
import makeRouter from 'cycle-route'
const router = makeRouter({
‘/’: ‘home’,
‘/foo/:bar’: ‘foo’,
‘*’: ‘notfound’ // default route
'/': 'home',
'/foo/:bar': 'foo',
'*': 'notfound' // default route
})
router(‘/’)
router('/')
```

@@ -42,5 +50,5 @@

```js
import { makePushStateDriver } from ‘cycle-pushstate-driver’
import makeRouter from ‘cycle-route’
import routes from ‘routes’
import { makePushStateDriver } from 'cycle-pushstate-driver'
import makeRouter from 'cycle-route'
import routes from 'routes'

@@ -60,3 +68,3 @@ const router = makeRouter(routes)

const navigate$ = DOM.select(‘a’).events(‘click’)
const navigate$ = DOM.select('a').events('click')
.map(e => e.currentTarget.pathname)

@@ -68,5 +76,5 @@

const pages = {
‘home’: homePage,
‘foo’: fooPage,
‘bar’: barPage
'home': homePage,
'foo': fooPage,
'bar': barPage
}

@@ -73,0 +81,0 @@ return pages[route.name]

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc