Vue Router 官网
安装
npm install vue-router@4
src\router\index.js
import { createRouter, createWebHistory } from "vue-router"
const routes = [
{
path: "/login", // http://localhost:5173/login
component: () => import("../views/admin/login.vue")
}
]
const router = createRouter({
history: createWebHistory(),
routes
})
export default router
src\main.js
import { createApp } from 'vue'
import App from './App.vue'
//路由
import router from './router' //导入路由模块
const app = createApp(App)
app.use(router) //将 Vue Router 插件注册到 Vue 应用中
app.mount('#app')
src\views\admin\login.vue
<script setup>
</script>
<template>
登录页
</template>
<style scoped>
</style>
src\App.vue
<script setup>
</script>
<template>
<router-view />
</template>
<style scoped>
</style>