no message
Former-commit-id: 13cddc6e80583fea2d48d618c9ff9de4d8e7dfea
This commit is contained in:
+10
-3
@@ -1,6 +1,8 @@
|
||||
import Vue from 'vue'
|
||||
import VueRouter from 'vue-router'
|
||||
|
||||
import store from '@/store/index'
|
||||
|
||||
import util from '@/libs/util.js'
|
||||
|
||||
// 路由数据
|
||||
@@ -18,15 +20,20 @@ const router = new VueRouter({
|
||||
* 权限验证
|
||||
*/
|
||||
router.beforeEach((to, from, next) => {
|
||||
// 验证当前路由所有的匹配中是否需要有登陆验证的
|
||||
// 关闭搜索面板
|
||||
store.commit('d2admin/search/set', false)
|
||||
// 验证当前路由所有的匹配中是否需要有登录验证的
|
||||
if (to.matched.some(r => r.meta.requiresAuth)) {
|
||||
// 这里暂时将cookie里是否存有token作为验证是否登陆的条件
|
||||
// 这里暂时将cookie里是否存有token作为验证是否登录的条件
|
||||
// 请根据自身业务需要修改
|
||||
const token = util.cookies.get('token')
|
||||
if (token && token !== 'undefined') {
|
||||
next()
|
||||
} else {
|
||||
// 没有登陆的时候跳转到登陆界面
|
||||
// 将当前预计打开的页面完整地址临时存储 登录后继续跳转
|
||||
// 这个 cookie(redirect) 会在登录后自动删除
|
||||
util.cookies.set('redirect', to.fullPath)
|
||||
// 没有登录的时候跳转到登录界面
|
||||
next({
|
||||
name: 'login'
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user