diff --git a/activitylink/src/router/index.js b/activitylink/src/router/index.js index e95e914..0912049 100644 --- a/activitylink/src/router/index.js +++ b/activitylink/src/router/index.js @@ -1,3 +1,4 @@ +import { ElMessage } from 'element-plus'; import { createRouter, createWebHistory } from 'vue-router' const routes = [ { @@ -75,5 +76,13 @@ const router = createRouter({ history: createWebHistory('/testBack/'), routes }) -// 导出 +router.beforeEach((to, from, next) => { + const token = localStorage.getItem("token"); + if (to.name != "homePage" && !token) { + next('/homePage'); + ElMessage.error('请先登录!'); + } + next(); +}) +// 暴露 export default router diff --git a/activitylink/src/views/zhongchou/index.vue b/activitylink/src/views/zhongchou/index.vue index c58431f..13223d2 100644 --- a/activitylink/src/views/zhongchou/index.vue +++ b/activitylink/src/views/zhongchou/index.vue @@ -1,4 +1,3 @@ -