Home  >  Q&A  >  body text

javascript - vue-router jump problem

vue-router
A page jumps to page B. Page B needs to be logged in. If you are not logged in, you need to jump to the login page, and then jump to page B. Now you can jump to the login page, but after logging in How to implement page b to jump to? Because page b is not a fixed page, it may be an exit page, user center page, etc.

仅有的幸福仅有的幸福2711 days ago512

reply all(4)I'll reply

  • 習慣沉默

    習慣沉默2017-05-19 10:37:53

    this.$router.go(-1);

    Return to the previous route ?

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-19 10:37:53

    Wouldn’t it be nice to go back to the previous page?

    reply
    0
  • PHP中文网

    PHP中文网2017-05-19 10:37:53

    This needs to be processed on the login page, when jumping to the login page

    http://登录页面URL/login?from=${encodeURLComponent(location.href)}

    In this way, on the login page, you can get the from parameter in queryString

    After the authentication is completed, it will be OK to jump back according to this from

    reply
    0
  • 为情所困

    为情所困2017-05-19 10:37:53

    Please refer to the router.beforeEachhook function in the vue-router official documentation, which can be used to implement your functions. The principle is probably:

    每次路由跳转都经过beforeEach这个钩子函数,里面的逻辑是若目的地是你需要先校验登录状态再跳转的页面,则检查登录态,检查通过则调用next(),否则跳转到登录页,并且带上的query是目的页面的fullPath,用于登录后跳转到目的页面用。

    If you have any questions, please chat privately~

    reply
    0
  • Cancelreply