import { createRouter, createWebHashHistory, createWebHistory, } from "vue-router"; import http from "../http.js"; import index from "@/views/index.vue"; import NotFound from "@/views/NotFound.vue"; const routes = [ { path: "/", component: index, meta: { title: "首页", requireAuth: true, // 标识该路由是否需要登录 }, }, { path: "/NotFound", name: "NotFound", component: NotFound, }, ]; const router = createRouter({ history: createWebHashHistory(), // history: createWebHistory(), routes, }); //路由守卫 router.beforeEach(async (to, from, next) => { if (to.path == "/") { next(); // var url = window.location.href; // var url = window.location.href; // var num = url.indexOf("?"); // if (num != -1) { // const dt = await http.get(getTokenUrl); // console.log(dt); // } // if (num == -1) { // // next("/NotFound"); // alert("无权限访问,请联系管理员"); // // return; // } else { // next(); // const dt = await http.get(getTokenUrl); // console.log(dt); // // if (dt.status_code !== 200) { // // // next("/NotFound"); // // alert("无权限访问,请联系管理员"); // // } else { // // next("/"); // // } // } } else { next(); } }); export default router;