vue3项目中如何配置路由

1.下载router,在router文件中引入相关依赖

npm init vite-app  项目名

cd 项目名

npm i

npm i vue-router

2.创建路由信息对象数组并对外抛出

3.在main.js使用use(router)方法,将路由管理器对象与当前vue项目相关联

4.在项目中设置路由router-link和路由出口router-view

常见面试题:route、routes、router的区别

route:一组路由信息对象

{path:'/foo',component:Foo}

routes:路由信息对象数组

const routes =[{path:'/foo',component:Foo},
{path:'/bar',component:Bar},
{path:'/user',component:User}

]

router:路由管理对象

 const router=createRouter({   })

posted @ 2022-05-12 12:49  蘑菇萌萌哒  阅读(119)  评论(0)    收藏  举报