search

Home  >  Q&A  >  body text

javascript - vue routing - What should I do if the browser return button repeatedly returns to the previously clicked page?

I have a homepage index. Click a button on the homepage to enter another page A. Due to functional requirements, I need to tab switch back and forth between page A and page B with the same jump. The problem now is my index , the three routes A and B are all at the same level, there is no secondary route.
In this way, when I click the return button on the browser or mobile phone, it will jump back and forth to the AB page, and finally return to the index.

This is what it looks like when you click, Index —> A —> B —> A —> B
This is what it looks like when you return, B —> A —> B —> A —> index

I want this effect: no matter how to switch between AB, it will eventually return to index
The return button on the web page can directly return to index, but the browser's own return will return based on the history, or Does Vue have a way to control the browser's back button.
Solution? ? ? ?

習慣沉默習慣沉默2709 days ago980

reply all(1)I'll reply

  • 大家讲道理

    大家讲道理2017-07-05 11:08:20

    router.replace(location)

    It is very similar to router.push, the only difference is that it does not add new records to history, but has the same name as its method - replaces the current history record.

    http://router.vuejs.org/zh-cn...

    reply
    0
  • Cancelreply