You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
820 B

// 引入必要的router组件
import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router'
// 引入视图
import HomeView from '../views/HomeView.vue'
// 创建路由,包含path,name,component属性, component属性可以使用箭头函数直接引入视图
const routes = [
{
path: '/',
name: 'home',
component: HomeView
},
{
path: '/about',
name: 'about',
component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
}
]
// 创建路由器,使用createRouter方法,传入history(路由类型)和 创建好的路由routes
// 路由类型分为hash型和html5型,分别为createWebHashHistory和createWebHistory
const router = createRouter({
history: createWebHistory(),
routes
})
// 导出路由
export default router