Vue in the browser Back Forward

Project development time, and sometimes we may need to page back and forward, this thing comes with browser forward and back functions much like, let's talk about roughly browser back and forward in vue

First, back function

vue in the back there is a good variety of methods can be used, before using these methods to be confirmed before the page, otherwise it back to an empty page!

Can be obtained by history.length history length

console.log(history.length)
1.window.history the object is stored in the history of pages visited, may not be used in the preparation of this prefix window. Load previous URL in the history list, click on it with the forward button in the browser is the same
window.history.back();   //后退1步
history.back();          //后退1步
2.this $ router.go (-1);. Vue performed by reverse routing step 1
this.$router.go(-2); //后退2步
this.$router.back(); //后退1步
Second, the forward function

By history.forward (); to load the next URL in the history list, click on it with the forward button in the browser is the same, there is need to make sure before using the next URL, or did not respond ~

Guess you like

Origin blog.csdn.net/weixin_34000916/article/details/90882695