You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 15, 2018. It is now read-only.
Your custom middleware can intercept this action to dispatch new actions in response to URL changes.
I have written a barebones middleware for routes with auth in their result. Like so:
exportconstauth=store=>next=>action=>{if(action.type===LOCATION_CHANGED&&action.payload&&action.payload.result&&action.payload.result.auth){constloggedIn=selectors.isLoggedIn(store.getState());if(!loggedIn){setTimeout(()=>{store.dispatch({type: PUSH,payload: '/login'});// Other dispatch which works perfectly// store.dispatch(fetchVocabsIfNeeded());},3000);}}returnnext(action);};
The setTimeout is just to simulate an async fetch that I would usually dispatch to the server to see if I had an active session. If not, then I want to go to the login page.
This seems to generate a ROUTER_PUSH action with a payload of '/login'. The route does not change and a fragment for '/login' is not displayed. However, if I dispatch that same action from an onClick on my App component, the result is a ROUTER_LOCATION_CHANGE with the payload of pathname, key, route, params, etc, and it works fine.
I am not experienced with redux middleware and suspect that this has something to do with the middleware chain and where redux-little-router sits in that chain, but I'm unsure how to address this. Should this be possible?