Redirecting in React/Redux
I'm currently working on a React project. It's the final project for Flatiron school.
One part of my project that I needed to do was redirect to another component. It's not technically a requirement for the project, however my goal is to build out this project to a fully functioning site that can actually help non-profits so I want it to work correctly.
I tried the documentation with regard to getting the history and passing it as a prop in the router. That didn't work. It would only redirect on a page refresh. I tried a few other options, each one seemed to be more convoluted than the previous. Import this, import that, make a new variable, and then finally, use history.push(url). Again, it would either not work at all or redirect on refresh only.
Finally, I figured it out. Thanks to this stack overflow page
https://stackoverflow.com/questions/42120822/function-call-after-page-reload-in-react
window.location = url
was the answer. It redirected to the component that I wanted it to. Success!
Looks like I still need
import createBrowserHistory from 'history/createBrowserHistory'
const history = createBrowserHistory()
One part of my project that I needed to do was redirect to another component. It's not technically a requirement for the project, however my goal is to build out this project to a fully functioning site that can actually help non-profits so I want it to work correctly.
I tried the documentation with regard to getting the history and passing it as a prop in the router. That didn't work. It would only redirect on a page refresh. I tried a few other options, each one seemed to be more convoluted than the previous. Import this, import that, make a new variable, and then finally, use history.push(url). Again, it would either not work at all or redirect on refresh only.
Finally, I figured it out. Thanks to this stack overflow page
https://stackoverflow.com/questions/42120822/function-call-after-page-reload-in-react
window.location = url
was the answer. It redirected to the component that I wanted it to. Success!
Looks like I still need
import createBrowserHistory from 'history/createBrowserHistory'
const history = createBrowserHistory()
<Router history={history}>
Comments
Post a Comment