Vue.js Routing with back button

simple way

<template lang="html">
  <div>   
    <button @click="goBack">
      Back
    </button>
  </div>
</template>
<script>
  export default {
    methods: {
      goBack() {
        this.$router.go(-1)
      }
    }
  }
</script>

When you are moving from your Home route to About route, you need to use <router-link> to navigate.

From your home page, you can navigate to about page as follows:

<router-link to="/about">Go to my About Page</router-link>

That generates a regular html anchor tag <a> with the path set correctly. When you click on that, it will take you to the about component, and not refresh the entire html webpage (with app scripts) from server.

When only the route component gets changed, all your other Vue params like token on the Vue instance will remain.

Please take a look at the vue-router here: http://router.vuejs.org/en/essentials/getting-started.html

Remember to have a placeholder for routes in your main app as follows: <router-view></router-view>. Your Home and About component will get rendered into this router-view as you change routes.


you can do something like this.$router.go(-1) or vm.$router.go(-1) to go forward this.$router.go(1) for more click here