| | |
| | | import { createRouter, createWebHashHistory } from "vue-router"; |
| | | import Home from "../views/Home.vue"; |
| | | 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: "/", |
| | | name: "Home", |
| | | component: Home, |
| | | component: index, |
| | | meta: { |
| | | title: "首页", |
| | | requireAuth: true, // 标识该路由是否需要登录 |
| | | }, |
| | | }, |
| | | { |
| | | path: "/about", |
| | | name: "About", |
| | | // 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(/* webpackChunkName: "about" */ "../views/About.vue"), |
| | | 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; |