0.0.4 • Published 7 years ago
@jsbit/spa-router v0.0.4
spa-router
- Tiny
- Not coupled to any rendering framework like React or Preact
- Can be used with rendering frameworks like react or preact :)
- Not coupled to any store like redux
- Can be used with stores like redux :)
- Supports nested routes (as deeply as you need, and with no requirement of nested path structure)
Annoyances
- Since updating a store like redux is not synchronous, during the time after
setCurrentRouteis called until the store actually gets updated, the component that is returned might not match the value in the store. If you have a way to solve this, let us know.
Example Usage
const routes = {
landing: {path: '/landing', component: Landing},
signup: {path: '/signup', component: SignUp}
}
const App = () =>
<div>
<MyRouter routes={routes} />
</div>API
router
- Returns a component that matches
currentPathand updates state with route details (like query params and dynamic path arguments)
Parameters
options: options objectoptions.routes: object of route defitionsoptions.currentPath: the current url path (with query string) (from your store)options.setCurrentRoute: function that should accept and savecurrentRoutein your storeoptions.currentRoute: the value that you saved insetCurrentRouteoptions.notFound: anything, will be returned when no matching route definition is found