Return to the previous position of the React page
P粉883278265
2023-08-29 23:54:13
<p>Imagine that I have a very long list called Page A. I scroll down to line 500. This row is also a link to page B, showing the details of the row. After checking the details on page B, I want to go back to page A, but I want to go back to the point where I went to page B, which is line 500. How can I achieve this behavior in a ReactJS application? </p>
This can be achieved in two ways.
I have listed method 1 here, suitable for beginners.
This can be achieved through id. I will list a sample html code like jsx
Assume the page usage is
www.samplepage.com
If I make the link concrete i.e.www.samplepage.com#1
It will take me to the first row, just like the anchor tag on the same page You can store the label in state and use it.You can also see similar implementations on github.