{"action":"opened","issue":{"url":"https://api.github.com/repos/ReactTraining/react-router/issues/4251","repository_url":"https://api.github.com/repos/ReactTraining/react-router","labels_url":"https://api.github.com/repos/ReactTraining/react-router/issues/4251/labels{/name}","comments_url":"https://api.github.com/repos/ReactTraining/react-router/issues/4251/comments","events_url":"https://api.github.com/repos/ReactTraining/react-router/issues/4251/events","html_url":"https://github.com/ReactTraining/react-router/issues/4251","id":193932940,"number":4251,"title":"V4: Redirect Auth example when fetching","user":{"login":"mmahalwy","id":3749095,"avatar_url":"https://avatars.githubusercontent.com/u/3749095?v=3","gravatar_id":"","url":"https://api.github.com/users/mmahalwy","html_url":"https://github.com/mmahalwy","followers_url":"https://api.github.com/users/mmahalwy/followers","following_url":"https://api.github.com/users/mmahalwy/following{/other_user}","gists_url":"https://api.github.com/users/mmahalwy/gists{/gist_id}","starred_url":"https://api.github.com/users/mmahalwy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mmahalwy/subscriptions","organizations_url":"https://api.github.com/users/mmahalwy/orgs","repos_url":"https://api.github.com/users/mmahalwy/repos","events_url":"https://api.github.com/users/mmahalwy/events{/privacy}","received_events_url":"https://api.github.com/users/mmahalwy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-12-07T01:21:56Z","updated_at":"2016-12-07T01:21:56Z","closed_at":null,"body":"When using `Redirect` with AJAX request, the initial state (using redux + redux-sagas) of `fetching` is `false`, and when mounting the react component, `Redirect` triggers a url redirect before an AJAX is triggered and `fetching` is `true`. \r\n\r\nExample:\r\n```\r\nApp.js\r\ncomponentWillMount() {\r\n    if (hasAuthStored()) {\r\n      return this.props.loadUser();\r\n    }\r\n\r\n    return false;\r\n  }\r\n\r\nrenderProtectedMatch = (MatchComponent) => {\r\n    const { fetching, user } = this.props;\r\n\r\n    return matchProps => (\r\n      !fetching && user ? (\r\n        <MatchComponent {...matchProps} />\r\n      ) : (\r\n        <Redirect\r\n          to={{\r\n            pathname: '/signin',\r\n            state: { from: matchProps.location }\r\n          }}\r\n        />\r\n      )\r\n    );\r\n  }\r\n\r\nrender() {\r\n return <Match pattern=\"/dashboard\" exactly render={this.renderProtectedMatch(Dashboard)} />\r\n}\r\n```"}}
{"actor":{"display_login":"mmahalwy"}}