How can vue perfectly solve the problem of monitoring the physical return of mobile phones and the return of pc browsers?

to briefly describe the scene, there are three pages of Agraine BMagol C. On page B, when the user presses return, the pop-up box confirms whether to return, click to return to A, click No to make no changes, page C cannot return to page B.
at present, Baidu has seen a lot of methods, but there are still minor problems.
my method is to add a url, exactly like page B using window.history.pushState and then use window.addEventListener ("popstate", this.nativeGoBack,false); to listen for the return, click OK to execute window.history.go (- 1). , click No to continue window.history.pushState.
use this.$router.replace to jump from B to C, although you can erase a B history, C can still return to B. No matter what, I just want to know how to clear B"s two history records? Although you can continue to listen in C and jump directly to A, the history of B always exists and can still be returned.
ask the gods how to solve this kind of similar problem, there are a lot of words, messy, please be patient. Show your strength

Feb.03,2022

history.pushState (null, null,'- sharp') OK, casually thinking, don't try


ide/advanced/navigation-guards.html-sharpglobal-guards" rel=" nofollow noreferrer "Vue Router Navigation Guards
the key points you mentioned can be easily realized with router.beforeEach by controlling next .

Menu