Closed easoncxz closed 4 years ago
With some tweaking around with peer dependencies of connected-react-router
, and sucking it up and using Provider
from react-redux
, I have things working:
It is decent, because I obtained the rendered route info from the Redux state:
<Switch>
<Route exact path="/" render={app} />
<Route
exact
path="/other"
render={() => (
<div>
<p>Another path</p>
<p>The current location is:</p>
<pre>{pretty(store.getState().router.location)}</pre>
<button onClick={() => store.dispatch(ConnRouter.push('/'))}>
Go home
</button>
</div>
)}
/>
</Switch>
The things that connected-react-router
forces me to do with my top-level state/Model
and action/Msg
types are quite hideous, but hey at least it works:
type ModelAndRouter = Redux.CombinedState<{
model: Model;
router: ConnRouter.RouterState<unknown>;
}>;
type MsgOrRouter = Msg | ConnRouter.RouterAction<unknown>;
const hist = createHashHistory();
const store: Redux.Store<ModelAndRouter, MsgOrRouter> = Redux.createStore(
Redux.combineReducers({
model: reducer,
router: ConnRouter.connectRouter(hist),
}),
undefined,
Redux.compose(Redux.applyMiddleware(ConnRouter.routerMiddleware(hist))),
);
Further developments: I figured out how to get just the history
package to do what I need. It's much simpler in terms of both concepts and APIs compared to the combination of:
See docs for history
here:
And my commit that implements this:
I don't want to put everything on the same page.
Found this blogpost introducing a demo library with appropriate ideology (i.e. "all state is kept in the store"):
Also seeming legit:
history
package.)react-redux
'sProvider
.Testing protocol:
Given an app set up with redux-router,
/home
, then the UI should show that page. (Testing outbound info-flow: libraries -> browser, via some kind of effect)push
action is dispatched, the browser transitions to that page. (Testing inbound info-flow: browser -> libraries, via some kind of subscription)Possibly relevant:
~Maybe best to just use react-router directly first, and worry about managing the location state in Redux later.~