import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router"; import UserLogin from "@/features/UserLogin/UserLogin.vue"; import MainLayout from "@/components/MainLayout/MainLayout.vue"; import ChangePassword from "@/features/ChangePassword/ChangePassword.vue"; import { resetStore, store } from "@/store/store"; const routes: RouteRecordRaw[] = [ { path: "/", component: UserLogin }, { path: "/login", component: UserLogin, name: "UserLogin" }, { path: "/", component: MainLayout, children: [ { path: "password", component: ChangePassword, }, ], }, { path: "/:pathMatch(.*)*", name: "NotFound", component: () => import("@/components/PageError404.vue"), }, ]; // 3. Create the router instance and pass the `routes` option // You can pass in additional options here, but let's // keep it simple for now. const router = createRouter({ // 4. Provide the history implementation to use. We are using the hash history for simplicity here. history: createWebHistory("oe-web"), routes, // short for `routes: routes` }); router.beforeEach((to, from, next) => { const loginPath = "/login/"; if (to.path) { _hmt.push(["_trackPageview", "/oe-web" + to.fullPath]); } if (to.path.match(/^\/?/) || to.path.match(/^\/login\/.?$/)) { resetStore(); next(); } else { if (!localStorage.getItem("domain")) { alert("地址出错,找不到机构!请关闭应用后重试!"); } if (!store.user.token) { next({ path: loginPath }); } else { next(); } } }); export default router;