退出再进入能回到原来的页面

195 阅读1分钟

思路分析

1. 登录成功之后,进入指定的目标页面(不要每次都进入主页)

2. 用户退出,跳入登录页时,携带目标页面地址告诉登录页

访问登录页,并且告诉它,登录成功之后要进入 /原来的页面

http://localhost:8080/#/login?return_url=/原来的页面

登录成功后路由跳转

this.router.push(this.router.push(this.route.query.return_url || '/')

return_url: 这个名字是自己约定的,它要和login/index.vue中跳转代码保持一致。

如何获取当前页面的地址 : this.$route.fullPath

this.$route.path只有路径的信息

this.$route.fullPath:路径+查询参数的信息

this.router.push(/login?returnurl=+encodeURIComponent(this.router.push('/login?return_url=' + encodeURIComponent(this.route.fullPath))

encodeURIComponent: 是js的内置API,用来对url进行编码 image.png