Vue Js go back to previous page:Vue.js is a progressive JavaScript framework that allows developers to build dynamic user interfaces. The window.history.back()
method is a built-in JavaScript function that allows you to navigate back to the previous page in the user’s browsing history. In a Vue.js application, this method can be used to implement a “go back” button or functionality that takes the user to the previous page they were on. By calling window.history.back()
within a Vue.js component method or event handler, the browser will navigate back to the previous page in the user’s history, allowing for seamless navigation and a better user experience.
How to enable “go back” functionality in Vue js?
The code you provided is a simple example of how to use Vue.js to go back to the previous page using the window.history
object.
The goBack()
method uses the window.history
object to go back to the previous page in the browser history. This is achieved by calling the back()
method on the history
object.
Overall, this is a simple and effective way to add a “Go Back” button to your Vue.js application.
Vue Js go back to previous page Example
<div id="app">
<h2>Vue js go back to previous page</h2>
<button @click="goBack">Go Back</button>
</div>
<script type="module">
const app = new Vue({
el: "#app",
methods: {
goBack() {
window.history.back();
}
}
})
</script>