Skip to content

Commit

Permalink
fix: Restore scroll restoration on beforeunload (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
taion authored Feb 6, 2019
1 parent de09e3b commit 6bbb7f0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ export default class ScrollBehavior {
this._oldScrollRestoration = window.history.scrollRestoration;
try {
window.history.scrollRestoration = 'manual';

// Scroll restoration persists across page reloads. We want to reset
// this to the original value, so that we can let the browser handle
// restoring the initial scroll position on server-rendered pages.
on(window, 'beforeunload', this._restoreScrollRestoration);
} catch (e) {
this._oldScrollRestoration = null;
}
Expand Down Expand Up @@ -127,7 +132,7 @@ export default class ScrollBehavior {
});
}

stop() {
_restoreScrollRestoration = () => {
/* istanbul ignore if: not supported by any browsers on Travis */
if (this._oldScrollRestoration) {
try {
Expand All @@ -136,6 +141,10 @@ export default class ScrollBehavior {
/* silence */
}
}
};

stop() {
this._restoreScrollRestoration();

off(window, 'scroll', this._onWindowScroll);
this._cancelCheckWindowScroll();
Expand Down

0 comments on commit 6bbb7f0

Please sign in to comment.