fix: set position

This commit is contained in:
Rogee
2024-12-13 17:05:51 +08:00
parent 7c52823610
commit 1fba1b1deb
8 changed files with 125 additions and 70 deletions

View File

@@ -1,55 +1,12 @@
import NotFound from '@/views/NotFound.vue'
import { useScrollPosition } from '@/stores/scroll-position'
import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/tabs/HomeView.vue'
import TabView from '../views/TabView.vue'
import routes from './routes'
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
{ path: '/:pathMatch(.*)*', name: 'NotFound', component: NotFound },
{
path: '/t/:tenant',
name: 'tab',
component: TabView,
children: [
{
path: '',
name: 'tab.home',
component: HomeView,
meta: {
title: '首页',
}
},
{
path: 'bought',
name: 'tab.bought',
component: () => import('../views/tabs/BoughtView.vue'),
meta: {
title: '已购买',
}
},
{
path: 'user',
name: 'tab.user',
// route level code-splitting
// this generates a separate chunk (About.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import('../views/tabs/UserView.vue'),
meta: {
title: '个人中心',
}
},
]
},
{
path: '/t/:tenant/play/:hash',
name: 'play',
component: () => import('../views/PlayView.vue'),
meta: {
title: '播放',
}
},
],
routes: routes,
})
router.beforeEach((to, from, next) => {
@@ -57,14 +14,14 @@ router.beforeEach((to, from, next) => {
name: from.name,
params: from.params,
}
console.log("from", from, "goto: ", to)
if (from.meta.keepAlive) {
const { setPosition } = useScrollPosition()
const scrollTop = document.documentElement.scrollTop;
setPosition(from.fullPath, scrollTop);
}
next()
// if (from.matched.length === 0) {
// next({ name: 'tab.home', params: to.params })
// } else {
// next()
// }
})
router.afterEach((to, from) => {