How to go back to the previous page in Vue.js

in Code Write a comment

Learn how to programmatically navigate back without reloading the page in Vue.js.

In Vue.js you can take advantage of the Vue Router methods.

router.go(n)

You can use router.go(n) method to programmatically navigate backwards or forward. It takes an integer as the only parameter that tells the method how many steps to go forward or backwards.

// go forward by one record, the same as history.forward()
router.go(1)

// go forward by 3 records
router.go(3)

To go back to the previous page use:

router.go(-1)

It will take use 1 step back, which is the same as history.back().


Hi, I'm Renat 👋

 


If you find this post useful, please let me know in the comments below. 
Cheers,
Renat Galyamov

Want to share this with your friends?
👉renatello.com/router-back-vue-js

PS: Make sure you check other Vue.js tutorials, e.g. how to set a default value for an HTML <select> tag in Vue.js or Top 5 CSS frameworks for your Vue.js project (2019).

Incoming search terms:

A collection of UI components for
Bootstrap 4/5 and Vue.js

Get now

Write a Comment

Comment