From ed4427243daa37c8c4480170926c970a34706262 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8A=B1=E8=A3=A4=E8=A1=A9?= Date: Fri, 7 Sep 2018 17:15:47 +0800 Subject: [PATCH] feature: add a redirect url when not logged in (#1046) Detail see #438 --- src/permission.js | 2 +- src/views/login/index.vue | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/permission.js b/src/permission.js index a20ceff6..81f9d113 100644 --- a/src/permission.js +++ b/src/permission.js @@ -52,7 +52,7 @@ router.beforeEach((to, from, next) => { if (whiteList.indexOf(to.path) !== -1) { // 在免登录白名单,直接进入 next() } else { - next('/login') // 否则全部重定向到登录页 + next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页 NProgress.done() // if current page is login will not trigger afterEach hook, so manually handle it } } diff --git a/src/views/login/index.vue b/src/views/login/index.vue index b2e61021..163be6d9 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -96,9 +96,19 @@ export default { }, passwordType: 'password', loading: false, - showDialog: false + showDialog: false, + redirect: undefined } }, + watch: { + $route: { + handler: function(route) { + this.redirect = route.query && route.query.redirect + }, + immediate: true + } + + }, created() { // window.addEventListener('hashchange', this.afterQRScan) }, @@ -119,7 +129,7 @@ export default { this.loading = true this.$store.dispatch('LoginByUsername', this.loginForm).then(() => { this.loading = false - this.$router.push({ path: '/' }) + this.$router.push({ path: this.redirect || '/' }) }).catch(() => { this.loading = false })