Vue3+Router4.X

安装 Vue Router

1
npm install vue-router@4

创建router文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// router.ts

import { createRouter, createWebHistory } from "vue-router";
import HelloWorld from "./components/HelloWorld.vue";


const routes = [
{ path: "/", component: HelloWorld },
{ path: "/cesium", component: () => import("./components/Cesium.vue") }
];

const router = createRouter({
history: createWebHistory(),
routes
});

export default router;

App.vue配置菜单

1
2
3
<router-link to="/cesium">
...
</router-link>

配置 main.ts

1
2
3
4
import Router from './router'
createApp(App)
.use(Router)
.mount('#app');