Invalid vue default route

const routes = [
  {
    path:"/HelloWorld",
    component: HelloWorld
  },
  {
    path: "/second",
    component: second
  },
  //
  {
    path: "/",
    redirect: HelloWorld
  }
]

A second route is always displayed when it comes in. Click to switch, and set the default HelloWorld to make the initial route invalid. What"s the matter? (beginners of vue)

Mar.04,2021

you don't pay attention to the document. Your redirect is used improperly. There are usually two ways:

  • Redirect path
const routes = [
  {
    path:"/HelloWorld",
    component: HelloWorld
  },
  {
    path: "/second",
    component: second
  },
  //
  {
    path: '/',
    redirect: '/HelloWorld'
  }
]
  • Redirect name
const routes = [
  {
    path:"/HelloWorld",
    name: 'helloworld',
    component: HelloWorld
  },
  {
    path: "/second",
    component: second
  },
  //
  {
    path: '/',
    redirect: { name: 'helloworld' }
  }
]
< hr >

reference documentation: https://router.vuejs.org/zh-c.

I hope my answer will be helpful to you!
Menu