How to solve the problem that Vue browser back can't trigger beforeRouteLeave?
This article introduces the knowledge of "Vue browser retreat cannot trigger beforeRouteLeave". In the actual case operation, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Phenomenon
When the first component is loaded (the first meaning here is the first browser history, later called the listening component), a normal jump to another page can trigger a beforeRouteLeave. However, pressing the browser's back button does not listen to the event.
Solution
At present, relatively native and impractical solutions are adopted. Add a layer of components, and then router.push to the listening component, so that the listening component is not the first component, and can listen to beforeRouteLeave events normally.
Note:
Due to disrupting the original route. Global routing snooping needs to be added to main.js
Router.beforeEach ((to, from, next) = > {if (to is' component for Jump'& & from is' component to be listened to) {router.go (- 1) next (false)} else {next ()} / / so that when you enter the component to be listened to from a normal page A When you press the return key in the listening component, you can enter A}) "how to solve the problem that the Vue browser can't trigger beforeRouteLeave?". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!