一、情景说明
在初学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路径对应的页面
博客主要讲述了Vue初学项目中,配置路由后页面出现告警的情景,告警含义为未配置路径对应的路由组件。同时给出了解决办法,通过关键配置,使访问页面时能自动重定向到路径对应的页面。
2955

被折叠的 条评论
为什么被折叠?



