Home  >  Q&A  >  body text

javascript - How to prevent browser rollback on a certain page in vue router?

I write a vue single-page application a>b>c. After successful login, the d page is displayed. I want to make the browser back button invalid on the d page. Please tell me how to implement it. I checked some global hooks using routing. I am currently using router hash. model

给我你的怀抱给我你的怀抱2669 days ago1403

reply all(3)I'll reply

  • 滿天的星座

    滿天的星座2017-06-30 09:59:27

    You can use router.replace(location) which will not add new records to history and replace the current history records.

    reply
    0
  • PHP中文网

    PHP中文网2017-06-30 09:59:27

    Case link

    //replace
    <router-link to="/D" replace>Go to D</router-link>
    or
    router.replace('D')

    reply
    0
  • 三叔

    三叔2017-06-30 09:59:27

    Use hooks inside components.

    beforeRouteEnter (to, from, next) {
      next(vm => {
        // 通过 `vm` 访问组件实例
      })
    }

    You can access this directly in beforeRouteLeave. This leave hook is usually used to prevent users from leaving suddenly before saving changes. Navigation can be canceled via next(false).
    From the documentation: https://router.vuejs.org/zh-c...

    reply
    0
  • Cancelreply