3.0.0 • Published 7 months ago

rawth v3.0.0

Weekly downloads
109
License
MIT
Repository
github
Last release
7 months ago
Pure functional isomorphic router based on streams. It works consistently on modern browsers and on node.

Build Status

NPM version NPM downloads Code Quality Coverage Status rawth size MIT License

Usage

Any rawth.route function creates an erre stream connected to the main router stream. These sub-streams will be activated only when their paths will match the current router path. For example:

import route, { router } from 'rawth'

route('/users/:user').on.value(({params}) => {
  const {user} = params

  console.log(`Hello dear ${user}`)
})

// you can dispatch router events at any time
router.push('/users/gianluca')

The argument passed to the subscribed functions is an URL object having params as additional property. The params array will contain all the matched route parameters

import route, { router } from 'rawth'

route('/:group/:user').on.value(({params}) => {
  const {group, user} = params

  console.log(`Hello dear ${user}, you are part of the ${group} group`)
})

// you can dispatch router events at any time
router.push('/friends/gianluca')

Unsubscribe streams

If you want to unsubscribe to a specific route you need just to end the stream

import route from 'rawth'

const usersRouteStream = route('/users/:user')

// subscribe to the stream as many times as you want
usersRouteStream.on.value(({params}) => { /* */ })
usersRouteStream.on.value(({params}) => { /* */ })
usersRouteStream.on.value(({params}) => { /* */ })

// end the stream
usersRouteStream.end()

Set the base path

You can set the base path and override the router default options using the configure method

import { configure } from 'rawth'

configure({
  base: 'https://example.com',
  strict: true
})
3.0.0

7 months ago

2.1.2

3 years ago

2.1.1

3 years ago

2.1.0

3 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago

0.0.0

5 years ago