npm i vue-router@next
createWebHashHistory为hash模式
1.新建router文件夹,index.ts
2.main.ts引入
index.ts文件:
import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";
const routes: Array = [
{
path: '/',
component: () => import('@/components/layout.vue')
}
]
const router = createRouter({
history: createWebHashHistory(),
routes: routes
})
export default router
main.ts文件:
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
createApp(App).use(router).mount('#app')