{"action":"created","issue":{"url":"https://api.github.com/repos/FormidableLabs/redux-little-router/issues/36","repository_url":"https://api.github.com/repos/FormidableLabs/redux-little-router","labels_url":"https://api.github.com/repos/FormidableLabs/redux-little-router/issues/36/labels{/name}","comments_url":"https://api.github.com/repos/FormidableLabs/redux-little-router/issues/36/comments","events_url":"https://api.github.com/repos/FormidableLabs/redux-little-router/issues/36/events","html_url":"https://github.com/FormidableLabs/redux-little-router/issues/36","id":172604452,"number":36,"title":"Dispatch in middleware does not use store-enhancer dispatch","user":{"login":"dpwrussell","id":1889043,"avatar_url":"https://avatars.githubusercontent.com/u/1889043?v=3","gravatar_id":"","url":"https://api.github.com/users/dpwrussell","html_url":"https://github.com/dpwrussell","followers_url":"https://api.github.com/users/dpwrussell/followers","following_url":"https://api.github.com/users/dpwrussell/following{/other_user}","gists_url":"https://api.github.com/users/dpwrussell/gists{/gist_id}","starred_url":"https://api.github.com/users/dpwrussell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dpwrussell/subscriptions","organizations_url":"https://api.github.com/users/dpwrussell/orgs","repos_url":"https://api.github.com/users/dpwrussell/repos","events_url":"https://api.github.com/users/dpwrussell/events{/privacy}","received_events_url":"https://api.github.com/users/dpwrussell/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/FormidableLabs/redux-little-router/labels/bug","name":"bug","color":"ee0701"},{"url":"https://api.github.com/repos/FormidableLabs/redux-little-router/labels/investigating","name":"investigating","color":"fbca04"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":9,"created_at":"2016-08-23T03:28:06Z","updated_at":"2016-09-29T14:28:38Z","closed_at":null,"body":"Hi,\r\n\r\nI am experimenting with this:\r\n\r\n> Your custom middleware can intercept this action to dispatch new actions in response to URL changes.\r\n\r\nI have written a barebones middleware for routes with `auth` in their `result`. Like so:\r\n\r\n```js\r\nexport const auth = store => next => action => {\r\n\r\n  if (\r\n    action.type === LOCATION_CHANGED &&\r\n    action.payload &&\r\n    action.payload.result &&\r\n    action.payload.result.auth\r\n  ) {\r\n\r\n    const loggedIn = selectors.isLoggedIn(store.getState());\r\n\r\n    if (!loggedIn) {\r\n      setTimeout(() => {\r\n        store.dispatch({\r\n          type: PUSH,\r\n          payload: '/login'\r\n        });\r\n        // Other dispatch which works perfectly\r\n        // store.dispatch(fetchVocabsIfNeeded());\r\n      }, 3000);\r\n    }\r\n  }\r\n  return next(action);\r\n};\r\n```\r\n\r\nThe `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.\r\n\r\nThis 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.\r\n\r\nI 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?\r\n\r\nCheers"},"comment":{"url":"https://api.github.com/repos/FormidableLabs/redux-little-router/issues/comments/250482551","html_url":"https://github.com/FormidableLabs/redux-little-router/issues/36#issuecomment-250482551","issue_url":"https://api.github.com/repos/FormidableLabs/redux-little-router/issues/36","id":250482551,"user":{"login":"philipyoungg","id":11477718,"avatar_url":"https://avatars.githubusercontent.com/u/11477718?v=3","gravatar_id":"","url":"https://api.github.com/users/philipyoungg","html_url":"https://github.com/philipyoungg","followers_url":"https://api.github.com/users/philipyoungg/followers","following_url":"https://api.github.com/users/philipyoungg/following{/other_user}","gists_url":"https://api.github.com/users/philipyoungg/gists{/gist_id}","starred_url":"https://api.github.com/users/philipyoungg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/philipyoungg/subscriptions","organizations_url":"https://api.github.com/users/philipyoungg/orgs","repos_url":"https://api.github.com/users/philipyoungg/repos","events_url":"https://api.github.com/users/philipyoungg/events{/privacy}","received_events_url":"https://api.github.com/users/philipyoungg/received_events","type":"User","site_admin":false},"created_at":"2016-09-29T14:28:38Z","updated_at":"2016-09-29T14:28:38Z","body":"The problem happens because with dispatch an action in store enhancer. It didn't follow the `apply middleware` generated dispatch action.\r\n\r\nWe can fix this by separating it to two parts: middleware and store enhancer.\r\n\r\nAdding the dispatch 'ROUTER_PUSH' to part of middleware should've fixed the problem."}}
{"actor":{"display_login":"philipyoungg"}}