javascript – How to return to the original location of the original page without reloading the page when you press the back button in AngularJS

Question: Question:

If you have created a SPA for routing with AngularJS, pressing the back button will return you to the previous page, but the page itself will be reloaded.

Therefore, it does not return to the display position of the previous page, and the data is reloaded.

How can I return to the original scroll position without reloading the previous page when I press the back button in AngularJS, just like a normal non-SPA application?

Answer: Answer:

For the scroll position, there is a method to record the position in the scroll event and restore it when it returns. The following answers will be helpful.

It seems that the problem that $ http.get is executed again can be solved by enabling cache.

$http.get('phones/phones.json', { cache: true })
Scroll to Top