-
Notifications
You must be signed in to change notification settings - Fork 114
Add replaceRoutes
on store
#88
Comments
Ooh, I dig this idea! I'll let you know when I start exploring it 👍 |
I implemented something to do exactly this a while ago, but I ran into some issues because of #96 initially, and even once I had patched middleware back in, it still is not sufficient to completely resolve this. This is what I did: I implemented some middleware to do split routes where a request which hits a route with a certain property would be intercepted, the bundle loaded and then on successful load, would replay the action. The problem with this is that it is difficult to access routes or matchRoute from the middleware as the store accessible in the middleware does not have access to these properties. The only way I've found to do this is to build the middleware with a closure, like this. const middleware = routes => store => next => action => {
...
} but then updating the route (Like this issue suggests) is tricky as you'd really need to replace store.routes, but there is no access to store to do that replace and as the routes are a closure and not accessed from the store, even if it was updated, the closure would not change unless that routes was a container object for the actual routes. It seems like there is a need to be able to get ahold of the Ideas very welcome! |
Implemented a |
Hi,
Have you ever though about a
replaceRoutes
method on the store ?The case study I have in mind is code splitting. In fact this case study is not only in my mind :
I am working on a web app (Typescript / React / Redux) and I'm currently switching from
react-router-redux
toredux-little-router
(because it will simplify a lot of stuff). Withreact-router
the routes object wasn't split becausereact-router
need all routes to boot.So with
redux-little-router
, I can do the same thing but I feel that maybe areplaceRoutes
is possible.What we could get is something like this :
redux-little-router
with one (or more) route ending with*
(likemyapp/private/*
).*
by some sub routes and then callstore.replaceRoutes(newRoutes)
that replace the route object internally and dispatch a route event.This would allow to:
The text was updated successfully, but these errors were encountered: