<Provider /> outside or <Router /> outside>?

Viewed 898

Usually(react-router + redux):

<Provider store={store}>
 <Router>
    <App />
 </Router>
</Provider>

Why not the other way around?

<Router>
  <Provider store={store}>
    <App />
  </Provider>
</Router>

Follow up question: to setup authentication, when LOGIN_SUCCESS action is fired, we need to save the returned token into window.localStorage and redirect the page. So I write success handler inside redux middleware:

const localStorageMiddleware = store => next => action => {
  if (action.type === 'LOGIN_SUCCESS') {
    if (!action.payload.error) {
      window.localStorage.setItem('jwt', action.payload.token)
    }
  } else if (action.type === 'LOGOUT_SUCCESS') {
    window.localStorage.setItem('jwt', '')
  }
  next(action)
}

Then I feel the need to access history.push to do redirect(that's why I ask the first question, trying to get access to location inside redux code), how do I do so?

1 Answers
Related