auto doesn't work when the page is back by history.go(-1)
Jack54s opened this issue · comments
Jack commented
When I go into a page from the page with Swipe and go back, the swipe's 'auto' property won't work. It will be okay if you touchmove it.
Forgive my poor English.
loup-brun commented
Hi! If you're running history.go
, I believe you are running a SPA or a webapp which doesn't reload the page – therefore, Swipe is not reloaded, and thus doesn't restart. You'll need to trigger the Swipe reload yourself.
My suggestion
I'm assuming a lot about the context here, since you didn't provide much information.
Pieces of the puzzle
- You should listen for a
popstate
event (basically, an event that fires when you dohistory.go
). - From the Swipe API, you can use the
.restart()
method, which will reload your Swipe instance with your config.
Example
// Create your swipe instance
window.mySwipe = new Swipe(/* your elem, config */)
// Add event listener to restart Swipe on 'popstate' (history) change
window.addEventListener('popstate', function (event) {
window.mySwipe.restart()
}, false)
Jack commented
Thanks. It's helpful.