An Interest In:
Web News this Week
- April 26, 2024
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
October 19, 2021 04:41 pm GMT
Original Link: https://dev.to/salehmubashar/how-to-use-react-history-in-react-js-8dl
How to use React History in React JS
Hi guys.
Ok so today we I will give you all the simple steps to use
Browser History in React JS.
Now you might be wondering, what is it for?
**React Router History **can be used to go to a previous page or to go to the appropriate response page, for example after the
a user logs in, he should be redirected to the dashboard page.
Step 1
Install react router dom.
npm install --save react-router-dom
Step 2
Import the history package from react router dom.
import { useHistory } from "react-router-dom"
Step 3
Assign the history function to a variable (not necessary but
recommended)
const history = useHistory()
Step 4
Use the push()
function to redirect the user after a successful login, for example.
history.push("/dashboard")
Here we are sending the user to the dashboard.
And there you go!.
Thank you all for reading this post.
If it was helpful, please consider following :)
Until next time
Bye!
Original Link: https://dev.to/salehmubashar/how-to-use-react-history-in-react-js-8dl
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To