From b92529a63e301fecd3c95c3455786057a58fcdd4 Mon Sep 17 00:00:00 2001 From: liyang <1711467488@qq.com> Date: Wed, 29 Aug 2018 11:23:10 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E9=99=86=E5=90=8E=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E9=87=8D=E5=AE=9A=E5=90=91=E5=88=B0=E4=B9=8B=E5=89=8D=E7=9A=84?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: 21da16e18630a8b3064f6bdd1b8cdd2c1b760439 [formerly 21da16e18630a8b3064f6bdd1b8cdd2c1b760439 [formerly 21da16e18630a8b3064f6bdd1b8cdd2c1b760439 [formerly 21da16e18630a8b3064f6bdd1b8cdd2c1b760439 [formerly 80fff8f10f84df7860d79293a4203c93c835ab7d [formerly 4058e66ecf06d1121f63f05950c7eba795ef4f43]]]]] Former-commit-id: 193dfc5044ad4be16c9de7ee233eb98a0b7d5090 Former-commit-id: 81588f7befd8834d0a908a0a21c8d51f4f64b0c5 Former-commit-id: 7175bd2c811fb738e3698d0d120e4292363e2315 [formerly e5dbd4dfdb31f6a8474843f57d3242d9d5d6734b] Former-commit-id: a9776650ed2f81a32d47389a04e0d914b6dab62b Former-commit-id: 983a77dffbfbd6c10b6943d953552333ac34f276 Former-commit-id: d582b38c28027aa7caa1a165c5ea457dbba97f8d Former-commit-id: 0b5c23c4b6ac208cc9dfe36b76211351a4b2de06 Former-commit-id: 584fa36572a92cabbb07640ed8ec741cc7a50bf4 --- src/router/index.js | 2 ++ src/store/modules/d2admin/modules/account.js | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index d5a6d886..38fc6878 100755 --- a/src/router/index.js +++ b/src/router/index.js @@ -26,6 +26,8 @@ router.beforeEach((to, from, next) => { if (token && token !== 'undefined') { next() } else { + // 将当前预计打开的页面完整地址临时存储 登陆后继续跳转 + // 这个 cookie(redirect) 会在登陆后自动删除 util.cookies.set('redirect', to.fullPath) // 没有登陆的时候跳转到登陆界面 next({ diff --git a/src/store/modules/d2admin/modules/account.js b/src/store/modules/d2admin/modules/account.js index ce545d01..3e28d6c2 100644 --- a/src/store/modules/d2admin/modules/account.js +++ b/src/store/modules/d2admin/modules/account.js @@ -41,8 +41,12 @@ export default { }, { root: true }) // 用户登陆后从持久化数据加载一系列的设置 commit('load') - // 更新路由 - vm.$router.replace(route) + // 更新路由 尝试去获取 cookie 里保存的需要重定向的页面完整地址 + const path = util.cookies.get('redirect') + // 根据是否存有重定向页面判断如何重定向 + vm.$router.replace(path ? { path } : route) + // 删除 cookie 中保存的重定向页面 + util.cookies.remove('redirect') }) .catch(err => { console.group('登陆结果')