vue-router 官网:https://router.vuejs.org/zh/
main.ts:
// 引入 vue-router
import * as VueRouter from "vue-router";
import routes from "./config/route"
// 创建 router 实例
const router = VueRouter.createRouter({
history: VueRouter.createWebHashHistory(),
routes,
})
// app 上使用 router 组件
app.use(router);
// 挂载 app
app.mount('#app');
./config/route
import Team from "../pages/Team.vue"
import Index from "../pages/Index.vue"
// 定义一些路由
const routes = [
{ path: '/', component: Index },
{ path: '/team', component: Team },
]
export default routes;
<template>
<div id="content">
<router-view/>
</div>
<router-link to="/">GO to Home</router-link>
<router-link to="/team">队伍</router-link>
</template>
<script>
export default {
name: "test"
}
</script>
<style scoped>
</style>