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
Pure functional isomorphic router based on streams. It works consistently on modern browsers and on node.
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:
importroute,{router}from'rawth'route('/users/:user').on.value(({params})=>{const{user}=paramsconsole.log(`Hello dear ${user}`)})// you can dispatch router events at any timerouter.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
importroute,{router}from'rawth'route('/:group/:user').on.value(({params})=>{const{group, user}=paramsconsole.log(`Hello dear ${user}, you are part of the ${group} group`)})// you can dispatch router events at any timerouter.push('/friends/gianluca')
Unsubscribe streams
If you want to unsubscribe to a specific route you need just to end the stream
importroutefrom'rawth'constusersRouteStream=route('/users/:user')// subscribe to the stream as many times as you wantusersRouteStream.on.value(({params})=>{/* */})usersRouteStream.on.value(({params})=>{/* */})usersRouteStream.on.value(({params})=>{/* */})// end the streamusersRouteStream.end()
Set the base path
You can set the base path and override the router default options using the configure method