react-redux redirect to other page after login
You can add
react-router-redux
which will conveniently add all routing info to the Redux state, but also you can usepush
fromreact-router-redux
by:dispatch(push('/dashboard'))
You can access it by
import { push } from 'react-router-redux'
I think you are not doing anything wrong with JWT. I would abstract your
fetch
call with the helper function. I assume you need to add your access token to all future requests after authorization, and using helper function you can do it easier and keep you code cleaner.
create a your own history
in history.js
file using this history library.
//history.js
import createHistory from 'history/createBrowserHistory'
const history = createHistory()
export default history
Supply it to your router:
<Router history = {history}>.....</Router>
Then you can use this history
object to redirect from anywhere. In your action:
import history from './history'
history.push(`${app}/dashboard`)