From 5d3c7637336dbfa314a3c092556d8327aa137d95 Mon Sep 17 00:00:00 2001 From: FloatingGhost Date: Sat, 6 Aug 2022 23:00:58 +0100 Subject: [PATCH 1/3] move to hash route --- src/boot/after_store.js | 5 ++++- src/boot/routes.js | 4 ++-- src/components/user_profile/user_profile.js | 9 +++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/boot/after_store.js b/src/boot/after_store.js index c4cddd5a..36020c23 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -376,9 +376,12 @@ const afterStoreSetup = async ({ store, i18n }) => { history: createWebHistory(), routes: routes(store), scrollBehavior: (to, _from, savedPosition) => { + console.log(to, _from) + console.log(savedPosition) if (to.matched.some(m => m.meta.dontScroll)) { - return false + return {} } + return savedPosition || { left: 0, top: 0 } } }) diff --git a/src/boot/routes.js b/src/boot/routes.js index cb2534c1..d762f057 100644 --- a/src/boot/routes.js +++ b/src/boot/routes.js @@ -58,7 +58,7 @@ export default (store) => { component: RemoteUserResolver, beforeEnter: validateAuthenticatedRoute }, - { name: 'external-user-profile', path: '/users/:id', component: UserProfile }, + { name: 'external-user-profile', path: '/users/:id', component: UserProfile, meta: { dontScroll: true } }, { name: 'interactions', path: '/users/:username/interactions', component: Interactions, beforeEnter: validateAuthenticatedRoute }, { name: 'dms', path: '/users/:username/dms', component: DMs, beforeEnter: validateAuthenticatedRoute }, { name: 'registration', path: '/registration', component: Registration }, @@ -75,7 +75,7 @@ export default (store) => { { name: 'list-timeline', path: '/lists/:id', component: ListTimeline }, { name: 'list-edit', path: '/lists/:id/edit', component: ListEdit }, { name: 'announcements', path: '/announcements', component: AnnouncementsPage }, - { name: 'user-profile', path: '/:_(users)?/:name', component: UserProfile } + { name: 'user-profile', path: '/:_(users)?/:name', component: UserProfile, meta: { dontScroll: true } } ] return routes diff --git a/src/components/user_profile/user_profile.js b/src/components/user_profile/user_profile.js index 982ac6ce..591324df 100644 --- a/src/components/user_profile/user_profile.js +++ b/src/components/user_profile/user_profile.js @@ -49,7 +49,7 @@ const UserProfile = { created () { const routeParams = this.$route.params this.load(routeParams.name || routeParams.id) - this.tab = get(this.$route, 'query.tab', defaultTabKey) + this.tab = get(this.$route, 'query.hash', defaultTabKey).replace(/^#/, '') }, unmounted () { this.stopFetching() @@ -146,7 +146,8 @@ const UserProfile = { }, onTabSwitch (tab) { this.tab = tab - this.$router.replace({ query: { tab } }) + console.log(this.$router) + this.$router.replace({ hash: `#${tab}` }) }, linkClicked ({ target }) { if (target.tagName === 'SPAN') { @@ -176,8 +177,8 @@ const UserProfile = { this.switchUser(newVal) } }, - '$route.query': function (newVal) { - this.tab = newVal.tab || defaultTabKey + '$route.hash': function (newVal) { + this.tab = newVal.replace(/^#/, '') || defaultTabKey } }, components: { -- 2.34.1 From a7e8a7a64ea86780eb2f17e75cea4c036bce67bb Mon Sep 17 00:00:00 2001 From: FloatingGhost Date: Thu, 11 Aug 2022 18:23:33 +0100 Subject: [PATCH 2/3] somewhat alleviate scroll-jumping --- src/boot/after_store.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/boot/after_store.js b/src/boot/after_store.js index 36020c23..c0a4cff9 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -376,8 +376,6 @@ const afterStoreSetup = async ({ store, i18n }) => { history: createWebHistory(), routes: routes(store), scrollBehavior: (to, _from, savedPosition) => { - console.log(to, _from) - console.log(savedPosition) if (to.matched.some(m => m.meta.dontScroll)) { return {} } -- 2.34.1 From 09a610e8689bc43cb83c99d10b81722dee3adf3f Mon Sep 17 00:00:00 2001 From: FloatingGhost Date: Thu, 11 Aug 2022 18:24:43 +0100 Subject: [PATCH 3/3] remove debug print --- src/components/user_profile/user_profile.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/user_profile/user_profile.js b/src/components/user_profile/user_profile.js index 591324df..b25a09d3 100644 --- a/src/components/user_profile/user_profile.js +++ b/src/components/user_profile/user_profile.js @@ -146,7 +146,6 @@ const UserProfile = { }, onTabSwitch (tab) { this.tab = tab - console.log(this.$router) this.$router.replace({ hash: `#${tab}` }) }, linkClicked ({ target }) { -- 2.34.1