一、安装
1. npm
- 默认
npm install vue-router -S
# 卸载
npm uninstall vue-router
- vite
# 安装
npm install vue-router@next -S
# 卸载
npm uninstall vue-router@next
2. yarn
- 默认
# 安装
yarn add vue-router -S
# 卸载
yarn remove vue-router
- vite
# 安装
yarn add vue-router@next -S
# 卸载
yarn remove vue-router@next
二、使用
2.1. 引入+注册
main.js
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
const app = createApp(App)
app.use(router).mount('#app')
2.2. 创建+配置
import {createRouter, createWebHistory} from "vue-router";
const routes = [
// 省略
]
const index = createRouter({
history: createWebHistory(),
routes
})
export default index