From a6d8550c833364df81630e6b26d92b5c05047fdb Mon Sep 17 00:00:00 2001 From: floatingghost Date: Thu, 11 Aug 2022 17:25:43 +0000 Subject: [PATCH] somewhat fix scrolling behaviour (#127) Reviewed-on: https://akkoma.dev/AkkomaGang/pleroma-fe/pulls/127 --- src/boot/after_store.js | 3 ++- src/boot/routes.js | 4 ++-- src/components/user_profile/user_profile.js | 8 ++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/boot/after_store.js b/src/boot/after_store.js index 0761792b..9a3d9904 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -377,8 +377,9 @@ const afterStoreSetup = async ({ store, i18n }) => { routes: routes(store), scrollBehavior: (to, _from, 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 6b935749..885b0b0d 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() @@ -152,7 +152,7 @@ const UserProfile = { }, onTabSwitch (tab) { this.tab = tab - this.$router.replace({ query: { tab } }) + this.$router.replace({ hash: `#${tab}` }) }, linkClicked ({ target }) { if (target.tagName === 'SPAN') { @@ -182,8 +182,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: {