import NotFound from '@/views/NotFound.vue' import { createRouter, createWebHistory } from 'vue-router' import HomeView from '../views/tabs/HomeView.vue' import TabView from '../views/TabView.vue' 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: '播放', } }, ], }) router.beforeEach((to, from, next) => { to.meta.from = { name: from.name, params: from.params, } console.log("from", from, "goto: ", to) next() // if (from.matched.length === 0) { // next({ name: 'tab.home', params: to.params }) // } else { // next() // } }) router.afterEach((to, from) => { document.title = to.meta.title || '' }) export default router