Detecting if switching using history API

Is there a consistent way to determine if a popstate was called by a Back or Back button click?

I am currently keeping the timestamp in the state when a new page is added, which means the navigation is working correctly for most parts, but if for example there are three pages loaded with history.push and the user navigates back to the second and refreshes its, the timestamp is updated and so the animation starts to get weirder because the forward now refers to the page with a lower timestamp, causing the animation to reverse.

The behavior can be reproduced at http://goo.gl/26MlRW by adding two screens, then going back once and refreshing the page.

Example code: http://goo.gl/pDGctA

+3


source to share


1 answer


Ok, I found a way to fix the error that was to look at the current history.state when the script was called, and if there was a timestamp in it, then use that as the current timestamp of the views, since the current state is actually passed between updates



+1


source







All Articles