|
@@ -12,15 +12,29 @@ const router = createRouter({
|
|
|
{
|
|
{
|
|
|
path: '/home',
|
|
path: '/home',
|
|
|
component: Home,
|
|
component: Home,
|
|
|
- name: 'wode'
|
|
|
|
|
|
|
+ name: 'wode',
|
|
|
|
|
+ meta: { title: '首页' }
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
path: '/my',
|
|
path: '/my',
|
|
|
- component: My
|
|
|
|
|
|
|
+ component: My,
|
|
|
|
|
+ meta: { title: '我的' },
|
|
|
|
|
+ beforeEnter: ((to, from) => {
|
|
|
|
|
+ const token = localStorage.getItem("token");
|
|
|
|
|
+ if (token) return true;
|
|
|
|
|
+ else return false
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ path: '/login',
|
|
|
|
|
+ name: "login",
|
|
|
|
|
+ meta: { title: '登录' },
|
|
|
|
|
+ component: () => import("../views/Login.vue")
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
path: '/list',
|
|
path: '/list',
|
|
|
component: List,
|
|
component: List,
|
|
|
|
|
+ // meta: { title: '列表' },
|
|
|
redirect: '/list/demo1',
|
|
redirect: '/list/demo1',
|
|
|
children: [
|
|
children: [
|
|
|
{
|
|
{
|
|
@@ -37,5 +51,17 @@ const router = createRouter({
|
|
|
},
|
|
},
|
|
|
]
|
|
]
|
|
|
});
|
|
});
|
|
|
|
|
+// router.beforeEach((to, form, next) => {
|
|
|
|
|
+// const whiteList = ['/home', '/login'];
|
|
|
|
|
+// const token = localStorage.getItem("token");
|
|
|
|
|
+// if (!token && !whiteList.includes(to.path)) {
|
|
|
|
|
+// console.log("进来")
|
|
|
|
|
+// next({ name: 'login' })
|
|
|
|
|
+// } else next()
|
|
|
|
|
|
|
|
|
|
+// })
|
|
|
|
|
+// router.afterEach((to, form, next) => {
|
|
|
|
|
+// console.log(to, 't')
|
|
|
|
|
+// document.title = to.meta.title || 'vue3'
|
|
|
|
|
+// })
|
|
|
export default router;
|
|
export default router;
|