Yet Another Redux React Router (YARRR)
This is just another router that keeps everything stored in the redux store. Right now, it expects the entire store to be using Immutable.js.
Install
yarn add yarrr
How to Use
Attach it to the router
key in your reducers:
;; ; ;
Create a list of all of your routes and pass it in as a prop to the <Router />
component.
;; const routes = path: '/' <Home /> path: '/dashboard' <Dashboard /> ; Component { return <div> <Router routes=routes /> </div> ; }
You can also get the matched route using the getMatchedRoute
selector.
; const getPage = { // get the matched route, return `null` if not found. const matchedRoute = ; // will return { path: '/dashboard', render: () => <Dashboard /> } if user is on `/dashboard` return matchedRoute;};
There is a <Link />
component that can be used to link to another route like so
<Link to="/" className="navigtion" replace=false>Home</Link>
Additionally, you can use the push
or replace
actions.
; const changePage = { ;}; const replacePage = { ;};