1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
| 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;
|
|