feature: add a redirect url when not logged in
https://github.com/PanJiaChen/vue-element-admin/issues/438
This commit is contained in:
		@@ -30,7 +30,7 @@ router.beforeEach((to, from, next) => {
 | 
			
		||||
    if (whiteList.indexOf(to.path) !== -1) {
 | 
			
		||||
      next()
 | 
			
		||||
    } else {
 | 
			
		||||
      next('/login')
 | 
			
		||||
      next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页
 | 
			
		||||
      NProgress.done()
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -66,7 +66,16 @@ export default {
 | 
			
		||||
        password: [{ required: true, trigger: 'blur', validator: validatePass }]
 | 
			
		||||
      },
 | 
			
		||||
      loading: false,
 | 
			
		||||
      pwdType: 'password'
 | 
			
		||||
      pwdType: 'password',
 | 
			
		||||
      redirect: undefined
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  watch: {
 | 
			
		||||
    $route: {
 | 
			
		||||
      handler: function(route) {
 | 
			
		||||
        this.redirect = route.query && route.query.redirect
 | 
			
		||||
      },
 | 
			
		||||
      immediate: true
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  methods: {
 | 
			
		||||
@@ -83,7 +92,7 @@ export default {
 | 
			
		||||
          this.loading = true
 | 
			
		||||
          this.$store.dispatch('Login', this.loginForm).then(() => {
 | 
			
		||||
            this.loading = false
 | 
			
		||||
            this.$router.push({ path: '/' })
 | 
			
		||||
            this.$router.push({ path: this.redirect || '/' })
 | 
			
		||||
          }).catch(() => {
 | 
			
		||||
            this.loading = false
 | 
			
		||||
          })
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user