import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router"; import { getCurrentInstance } from "vue"; export const Layout = () => import("@/layout/index.vue"); // 静态路由 export const constantRoutes: RouteRecordRaw[] = [ // 登录 { path: "/login", component: () => import("@/views/login/index.vue"), meta: { hidden: true }, name:'login' }, { path: "/signSucceed", component: () => import("@/views/signSucceed/index.vue"), meta: { hidden: true }, }, // 创建视频 { path: "/", component: Layout, redirect: "/createVideo", children: [ { path: "createVideo", component: () => import("@/views/createVideo/index.vue"), name: "createVideo", meta: { title: "createVideo", icon: "homepage", affix: true, name: "createVideo.title", }, }, ], }, // 视频列表 { path: "/", component: Layout, redirect: "/myCreating", children: [ { path: "myCreating", component: () => import("@/views/myCreating/index.vue"), name: "myCreating", meta: { title: "myCreating", icon: "homepage", affix: true, name: "myCreating.title", }, }, ], }, // 定制分身 { path: "/", component: Layout, redirect: "/userModel", children: [ { path: "userModel", component: () => import("@/views/userModel/index.vue"), name: "userModel", meta: { title: "userModel", icon: "homepage", affix: true, name: "userModel.title", }, }, ], }, // 定制声纹 { path: "/", component: Layout, redirect: "/voiceModel", children: [ { path: "voiceModel", component: () => import("@/views/voiceModel/index.vue"), name: "voiceModel", meta: { title: "voiceModel", icon: "homepage", affix: true, name: "voiceModel.title", }, }, ], }, { path: "/", component: Layout, redirect: "/myStore", children: [ { path: "myStore", component: () => import("@/views/myStore/index.vue"), name: "myStore", meta: { title: "myStore", icon: "homepage", affix: true, name: "myStore.title", }, }, ], }, { path: "/", component: Layout, redirect: "/myAPI", children: [ { path: "myAPI", component: () => import("@/views/myAPI/index.vue"), name: "myAPI", meta: { title: "myAPI", icon: "homepage", affix: true, name: "API.title", }, }, ], }, { path: "/", component: Layout, redirect: "/moveImg", children: [ { path: "moveImg", component: () => import("@/views/moveImg/index.vue"), name: "moveImg", meta: { title: "moveImg", icon: "homepage", affix: true, name: "moveImg.title", }, }, ], }, ]; /** * 创建路由 */ const router = createRouter({ history: createWebHashHistory(), routes: constantRoutes as RouteRecordRaw[], // 刷新时,滚动条位置还原 // 2023-5-23 添加平滑滚动 YWQ scrollBehavior: () => ({ behavior: "smooth", left: 0, top: 0 }), }); /** * 重置路由 */ export function resetRouter() { router.replace({ path: "/login" }); } export default router;