先安装路由
npm i vue-router
//创建路由器
import { createRouter, createWebHashHistory } from 'vue-router'//1.导入组件
import Home from '@/components/Home.vue'
import News from '@/components/News.vue'//2.配置路由映射规则
const routes = [{name: 'home',path: '/home',component: Home},{name: 'news',path: '/news',component: News}
]//路由器管理路由
const router = createRouter({//路由器的工作模式history: createWebHashHistory(), routes: routes
})//并暴露路由器,供main.ts调用
export default router