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.
48 lines
1.3 KiB
48 lines
1.3 KiB
1 year ago
|
// 引入必要的router组件
|
||
|
import {createRouter, createWebHashHistory, createWebHistory} from 'vue-router'
|
||
|
// 引入视图
|
||
|
import HomeView from '../views/HomeView.vue'
|
||
|
|
||
|
const Header = () => import('../views/HeaderView.vue')
|
||
|
const Test = () => import('../views/TestView.vue')
|
||
|
|
||
|
// 创建路由,包含path,name,component属性, component属性可以使用箭头函数直接引入视图
|
||
|
const routes = [
|
||
|
{
|
||
|
path: '/',
|
||
|
name: 'home',
|
||
|
component: HomeView
|
||
|
},
|
||
|
{
|
||
|
path: '/about',
|
||
|
name: 'about',
|
||
|
component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
|
||
|
},
|
||
|
// 配合params参数的路由path改造
|
||
|
{
|
||
|
path: '/about/:id/:name',
|
||
|
name: 'about-params',
|
||
|
component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
|
||
|
},
|
||
|
{
|
||
|
path: '/header',
|
||
|
name: 'header',
|
||
|
component: Header,
|
||
|
},
|
||
|
{
|
||
|
path: '/test',
|
||
|
name: 'test',
|
||
|
component: Test,
|
||
|
}
|
||
|
]
|
||
|
|
||
|
// 创建路由器,使用createRouter方法,传入history(路由类型)和 创建好的路由routes
|
||
|
// 路由类型分为hash型和html5型,分别为createWebHashHistory和createWebHistory
|
||
|
const router = createRouter({
|
||
|
history: createWebHistory(),
|
||
|
routes
|
||
|
})
|
||
|
|
||
|
// 导出路由
|
||
|
export default router
|