Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

vue 3 router redirect

// 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
});
Source by router.vuejs.org #
 
PREVIOUS NEXT
Tagged: #vue #router #redirect
ADD COMMENT
Topic
Name
6+6 =