// Use this in a lifecycle method
this.$router.push('/login');
// nuxtjs
this.$router.push({ name: 'routename' })
// Vue Router alias and redirect
import { createWebHistory, createRouter } from "vue-router";
// An alias means when a user visit that alias "/home" instead of "/",
// the url will stay the same.
// But, it will be matched as if the user is visiting "/" instead of "/home"
const routes = [
{
path: '/',
alias: '/home',
Name: 'home',
component: homePage
}
];
// A redirect means when the user visits "/home",
// the URL will be replaced by /, and then matched as /
const routes = [
{
path: '/',
Name: 'home',
component: homePage
},
{
path: '/home', // you can also use wildcards such as /:catchAll(.*)
redirect: '/'
}
];
// then create your router
const router = createRouter({
history: createWebHistory(),
routes
});