diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2020-02-06 22:10:33 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2020-02-06 22:10:33 +0900 |
| commit | 9e68eefbb725b8fa01832b063a1345e2f1db061e (patch) | |
| tree | 39083c325a58798be5ab9df82f15fd78f3b70497 | |
| parent | Improve messaging form (diff) | |
| download | sharkey-9e68eefbb725b8fa01832b063a1345e2f1db061e.tar.gz sharkey-9e68eefbb725b8fa01832b063a1345e2f1db061e.tar.bz2 sharkey-9e68eefbb725b8fa01832b063a1345e2f1db061e.zip | |
Resolve #5859
| -rw-r--r-- | src/client/router.ts | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/client/router.ts b/src/client/router.ts index 82451260c3..16ab96dea4 100644 --- a/src/client/router.ts +++ b/src/client/router.ts @@ -6,6 +6,8 @@ Vue.use(VueRouter); const page = (path: string) => () => import(`./pages/${path}.vue`).then(m => m.default); +let indexScrollPos = 0; + export const router = new VueRouter({ mode: 'history', routes: [ @@ -55,13 +57,19 @@ export const router = new VueRouter({ // なんかHacky // 通常の使い方をすると scroll メソッドの behavior を設定できないため、自前で window.scroll するようにする // setTimeout しないと、アニメーション(トランジション)の関係でうまく動かない - scrollBehavior(to, from, savedPosition) { + scrollBehavior(to) { window._scroll = () => { // さらにHacky - if (savedPosition) { - window.scroll({ top: savedPosition.y, behavior: 'instant' }); + if (to.name === 'index') { + window.scroll({ top: indexScrollPos, behavior: 'instant' }); } else { window.scroll({ top: 0, behavior: 'instant' }); } }; } }); + +router.afterEach((to, from) => { + if (from.name === 'index') { + indexScrollPos = window.scrollY; + } +}); |