Vue3:用重定向方式,解决No match found for location with path “/“问题

一、情景说明

在初学Vue3的项目中,我们配置了路由后,页面会告警
如下图:
在这里插入图片描述
具体含义就是,没有配置"/"路径对应的路由组件

二、解决

关键配置:redirect

const router = createRouter({
  history:createWebHistory(), //路由器的工作模式(稍后讲解)
  routes:[ //一个一个的路由规则
    {
      name:'zhuye',
      path:'/home',
      component:Home
    },
    {
      name:'xinwen',
      path:'/news',
      component:News,
      children:[
        {
          name:'xiang',
          path:'detail',
          component:Detail,
          props(route){
            return route.query
          }
        }
      ]
    },
    {
      name:'guanyu',
      path:'/about',
      component:About
    },
    {
      path:'/',
      redirect:'/home'
    }
  ]
})

这样,一访问页面,就自动重定向到/home路径对应的页面

相关推荐

  1. VUE3中路由常配置及常见问题解决方法

    2024-03-24 05:14:01       41 阅读
  2. linux输出的定向无效问题解决

    2024-03-24 05:14:01       43 阅读
  3. vue路由定向

    2024-03-24 05:14:01       14 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-24 05:14:01       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-24 05:14:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-24 05:14:01       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-24 05:14:01       20 阅读

热门阅读

  1. PTA家庭房产

    2024-03-24 05:14:01       17 阅读
  2. 最长公共前缀

    2024-03-24 05:14:01       16 阅读
  3. 网络安全防御策略

    2024-03-24 05:14:01       19 阅读
  4. MySQL的For Update行级锁

    2024-03-24 05:14:01       22 阅读
  5. 【Redis底层原理】之数据结构与持久化机制

    2024-03-24 05:14:01       23 阅读
  6. 蓝桥杯每日一题:修建灌木

    2024-03-24 05:14:01       20 阅读
  7. k8s etcdctl 备份

    2024-03-24 05:14:01       20 阅读
  8. Vue2的生命周期

    2024-03-24 05:14:01       16 阅读
  9. 华为OD机试 C++ -采样过滤

    2024-03-24 05:14:01       19 阅读
  10. im-system 第八章

    2024-03-24 05:14:01       20 阅读
  11. vue3父组件给子组件传值,并在子组件接受

    2024-03-24 05:14:01       19 阅读