move to hash route

This commit is contained in:
FloatingGhost 2022-08-06 23:00:58 +01:00
parent cbf883ab1e
commit 5d3c763733
3 changed files with 11 additions and 7 deletions

View file

@ -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 }
}
})

View file

@ -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

View file

@ -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: {