-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
101 lines (97 loc) · 2 KB
/
index.ts
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import Vue from "vue";
import VueRouter, { RouteConfig } from "vue-router";
// Views //
import BlogFrame from "@/views/blog/frame.vue";
import store from '@/store';
Vue.use(VueRouter);
const routes: Array<RouteConfig> = [
{
path: "/",
component: BlogFrame,
children: [
{
path: "",
name: "BlogHome",
component: () => import(
/* webpackChunkName: "blog-home" */
"@/views/blog/home.vue"
)
},
{
path: "category/:id",
name: "BlogCategory",
component: () => import(
/* webpackChunkName: "blog-category" */
"@/views/blog/category.vue"
)
},
{
path: "post/:id",
name: "BlogPost",
component: () => import(
/* webpackChunkName: "blog-post" */
"@/views/blog/post.vue"
)
}
]
},
{
"path": "/admin",
component: () => import(
/* webpackChunkName: "admin-frame" */
"@/views/admin/frame.vue"
),
children: [
{
path: "",
name: "AdminBasic",
component: () => import(
/* webpackChunkName: "admin-basic" */
"@/views/admin/basic.vue"
)
},
{
path: "bloghome",
name: "AdminBlogHome",
component: () => import(
/* webpackChunkName: "admin-blog-home" */
"@/views/admin/blog-home.vue"
)
},
{
path: "category",
name: "AdminCategory",
component: () => import(
/* webpackChunkName: "admin-category" */
"@/views/admin/category.vue"
)
}
]
},
{
path: "/admin/editor",
name: "BlogEditor",
component: () => import(
/* webpackChunkName: "blog-editor" */
"@/views/blog/editor.vue"
)
}
];
const router = new VueRouter(
{
mode: "history",
base: process.env.BASE_URL,
routes
}
);
router.beforeEach((to, from, next) => {
if (to.fullPath.startsWith("/admin")) {
setTimeout(() => {
if (!store.getters["isAdmin"]) {
if (from.fullPath.startsWith("/admin")) next({ name: "BlogHome" });
else next({ path: from.fullPath as string });
} else next();
}, from.name == null ? 1000 : 0);
} else next();
});
export default router;