vue中如何配置路由?
src文件下新建router文件夹 建index.js
import{createRouter,createWebHashHistory} from 'vue-router'
import Bar from "./components/Bar.vue";
import Foo from "./components/Foo.vue";
import User from "./components/User.vue";
//创建路由信息对象数组
const routers=[
{path:'/foo',component:Foo},//router 每一组路由信息对象
{path:'/bar',component:Bar},
{path:'/user',component:User}
]
//创建路由管理对象
const router=createRouter({
history:createWebHashHistory(),
routes
})
//将路由管理器对象对外抛出
export default router;
常见面试题目 :route, routes, router的区别
route:一组路由信息对象
{path:'/foo',component:Foo}
routes:路由信息对象数组
const routers=[
{path:'/foo',component:Foo},
{path:'/bar',component:Bar},
{path:'/user',component:User}
]
router: 路由管理对象
const router =createRouter({})

浙公网安备 33010602011771号