1.2.1 • Published 2 months ago

@sruth/router v1.2.1

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
2 months ago

Sruth Router

A routing library for Sruth.

npm i @sruth/core @sruth/router rxjs

API

navigate :: (path, options?) -> void

Navigates to the specified path.

Accepts the following options:

  • replace (optional, default false): whether to replace the current entry in the history or add a new one.
  • search (optional, default ''): search part of the url.
navigate('/some/path', { search: '?query=true' })

router :: (pages, factory) -> Observable

Takes an array of pages and an observable factory and returns a function that you can pass to subscribe.

import { subscribe } from '@sruth/core'
import { router } from '@sruth/router'

const pages = [
	{ path: '/' },
	{
		path: '/joke',
		run: () => {
			someEffect()
			return () => someCleanup()
		}
	},
	{ path: '/not-found', fallback: true }
]

const factory = router(routes, otherStateFactory)
const patch = state => vdom(state)

subscribe(patch, factory)

Each page can have the following properties:

  • fallback (optional): set to true in order to fall back to a specific page if no match is found.
  • path: the path to match the route.
  • run (optional): a function to run when navigating to the page. It can optionally return a new function that will the executed when navigating away from the page.
  • view (optional): a function that accepts state and location options (params and query); designed to be used to create a component to be rendered in the view.
1.2.1

2 months ago

1.2.0

3 months ago

1.1.1

10 months ago

1.1.3

10 months ago

1.1.2

10 months ago

1.1.0

1 year ago

1.0.0

2 years ago

1.0.0-rc.1

2 years ago