Skip to content

Commit

Permalink
feature: add a redirect url when not logged in (#1046)
Browse files Browse the repository at this point in the history
Detail see #438
  • Loading branch information
PanJiaChen authored Sep 7, 2018
1 parent 9c5352e commit ed44272
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
14 changes: 12 additions & 2 deletions src/views/login/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
Expand All @@ -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
})
Expand Down

0 comments on commit ed44272

Please sign in to comment.