VUE如何配置没有的路由

routes: [

{
  path: '/',
  name: 'index',
  component: index
},
{
  path: '/sectionOne',
  name: 'sectionOne',
  component: sectionOne
}

]

现在的路由。 怎么配置 进入到'/djodqjd'的时候进入index

阅读 3.4k
5 个回答
    {path:'/index',component:a},
    {path:'/due',component:b},
    {path:'/used',component:c},
    {path:'*',redirect:'/index'}//这里就是配置没有的路由和默认的路由

在最后加一个,放到最后是因为优先级最低,前边的匹配不到才会进入默认的index.

{
  path: '/',
  name: 'index',
  component: index
},
{
  path: '/sectionOne',
  name: 'sectionOne',
  component: sectionOne
},
{
   path: '/*',
   component: index
}

编程式路由 去看官方文档

题主可以这样来进行配置

{
  path: '/',
  name: 'index',
  component: index
},
{
  path: '/sectionOne',
  name: 'sectionOne',
  component: sectionOne
},
{
   path: '/djodqjd',
   component: Djodqjd,
   redirect: '/index', 
}

通过redirect,当进入路由djodqjd的时候,就直接重定向到index

你的意思是进入404页面吧,可以如下配置,输入路由表中不存在的路由,都会进入该404_index组件页面,但是要放路由表中的最后面

{
   path: '*',
   component: 404_index
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题