I am using router.back() with the vue-router. It works but the problem I can foresee happening is that a user might visit the page without a history by directly accessing. That or the user is coming from another domain.
Both scenarios are unwanted. In case of the previous route not being a proper Vue route, I want to provide an alternative.
So in that case instead of router.back(), I want to push something like this.$router.push({ name: 'deal-list' });
I know the routes can be check with route.beforeEach and I am already using it with my router.js file to maintain my query parameters like so:
router.beforeEach((to, from, next) => {
if (!hasQueryParams(to) && hasQueryParams(from)) {
next({ name: to.name, query: from.query });
}
next();
});
How would I check within a component though what the previous route is and adjust my link accordingly?