import { createRouter, createWebHistory } from "vue-router"; import { ChatRound } from '@element-plus/icons-vue' const routes = [ { path: "/", component: () => import("@/layouts/MainLayout.vue"), children: [ { path: "", name: "blank", meta: { hidden: true, }, component: () => import("@/layouts/blank.vue"), }, ], }, { path: "/chat", component: () => import("@/layouts/MainLayout.vue"), children: [ { path: "", name: "chat", meta: { icon: ChatRound }, component: () => import("@/views/chat/index.vue"), }, ], }, ]; export const router = createRouter({ history: createWebHistory(), routes, }); // 添加全局前置守卫 router.beforeEach((to, from, next) => { // 如果访问根路径,重定向到/chat if (to.path === '/') { next('/chat') } else { next() } }) export default router;