javascript - How can I listen to back/forward button click in my SPA? -
i have backbone app, uses backbone.history.start({pushstate: true}). render pages based on url change, , forward buttons work fine, views rendered well.
there problem though, page scroll positions are't kept when click or forward button. makes feel bad.
i thought keep array of pages visited , store scroll position each of them. listen if user click back/forward , load appropriate scroll position.
but.
i found out unable tell when user click or forward button. if could, read stored scroll position of previous page , apply it. doing wrong?
you store scroll location part of route, using like:
router.navigate('/my/route/scroll/[my_scroll_location]', {replace: true});
so won't add new history point, modify current one. way, when hit "back" go previous "page"/route, , hitting "forward" have enough information scroll right point.
Comments
Post a Comment