client/router: remember scroll position
This commit is contained in:
parent
e10ed4bce8
commit
95b3b09cbc
|
@ -5,15 +5,14 @@ const misc = require('./util/misc.js');
|
||||||
|
|
||||||
const router = require('./router.js');
|
const router = require('./router.js');
|
||||||
|
|
||||||
const origPushState = router.Context.prototype.pushState;
|
history.scrollRestoration = 'manual';
|
||||||
router.Context.prototype.pushState = function() {
|
|
||||||
window.scrollTo(0, 0);
|
|
||||||
origPushState.call(this);
|
|
||||||
};
|
|
||||||
|
|
||||||
router.exit(
|
router.exit(
|
||||||
/.*/,
|
/.*/,
|
||||||
(ctx, next) => {
|
(ctx, next) => {
|
||||||
|
ctx.state.scrollX = window.scrollX;
|
||||||
|
ctx.state.scrollY = window.scrollY;
|
||||||
|
ctx.save();
|
||||||
views.unlistenToMessages();
|
views.unlistenToMessages();
|
||||||
if (misc.confirmPageExit()) {
|
if (misc.confirmPageExit()) {
|
||||||
next();
|
next();
|
||||||
|
@ -26,6 +25,12 @@ router.enter(
|
||||||
(ctx, next) => {
|
(ctx, next) => {
|
||||||
mousetrap.reset();
|
mousetrap.reset();
|
||||||
next();
|
next();
|
||||||
|
window.requestAnimationFrame(
|
||||||
|
() => {
|
||||||
|
window.scrollTo(
|
||||||
|
ctx.state.scrollX || 0,
|
||||||
|
ctx.state.scrollY || 0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
let controllers = [];
|
let controllers = [];
|
||||||
|
|
Loading…
Reference in New Issue