FormidableLabs / redux-little-router

A tiny router for Redux that lets the URL do the talking.
MIT License
1.04k stars 114 forks source link

temporarily block transitions #237

Closed ggrillone closed 6 years ago

ggrillone commented 6 years ago

Hi,

In the app i'm working on there is a use case where we need to wait for some other code to run before a transition occurs. My first attempt at this was to add in some custom middleware, which looks something like:

customMiddleware = store => next => action => {
    if (store.getState().appState.state === 'STARTING' && action.type === 'ROUTER_LOCATION_CHANGED') {
         action.type = 'ROUTER_PUSH'

         return  next(action)
     } else {
       // cont...
       return next(action);
    }
}

As you can see I am essentially moving the routing action type back 1 step so it comes back around and checks if the condition is met before continuing. It doesn't seem to have any strange side-effects and from looking through the code in your repo it doesn't appear that it will cause any issues. But it just kind of feels weird, and just wondering if this is a bad practice with your library? Or anything internally that could be tripped up that I missed when looking through the code base?

Thanks

tptee commented 6 years ago

Check out the block and unblock action creators in v14.3.0!