Question: I want to get previous page link or url in `vue-router`. Like a this. How to do it?

```
const link = this.$router.getPrevLink(); // function is not exist?
this.$router.push(link);

```

Near concept is `this.$router.go(-1)`.

```
this.$router.go(-1);

```

Answer: 
This routing solution will fall back to a static url if a previous url does not exist.

```
<template>
    <div>
        <router-link :to="prevRoutePath">Previous Page</router-link>
        <router-link to="/">Home Page</router-link>
    </div>
</template>

<script>
export default {
    beforeRouteEnter(to, from, next) {
        next(vm => {
            vm.prevRoute = from;
        });
    },
    computed: {
        prevRoutePath() {return this.prevRoute ? this.prevRoute.path : '/'},
    }
}
</script>

```
For Vue 2.6 that works for me:

In-App.vue component when you initialize the VueRouter you can get from and to details as below:

```
export const globalState = Vue.observable({ from: {}, to: {} });
const router = new VueRouter({
    base: '/',
    routes: routes,
    mode: 'history',
    scrollBehavior(to, from, savedPosition) {
        Vue.set(globalState, 'from', from);
        Vue.set(globalState, 'to', to);
        return { x: 0, y: 0 };
    },
});

```

routes are ur routes and each time u navigate to a different URL you will have all from and to routes details.
Then u can import the `globalState` object and use it like that

```
     import { globalState } from './app';
     goBack() {
        const lastPath = globalState.from?.fullPath;
        const currentPath = globalState.to?.fullPath;
        if (lastPath && currentPath !== lastPath) 
           {
              this.$router.push(lastPath);
           } else {
              this.$router.push('another-path');
            }
        }

```