1.安装vue-router路由
npm install vue-router@4 --save
2.路由使用
在src下新建router.js文件
import {createRouter,createWebHashHistory} from "vue-router"
const Login = () => import( /* webpackChunkName: "login" */ '@/views/users/Login.vue');
const routes=[
{
path: '/login',
name: 'Login',
component: Login,
meta: {
title: '登录'
}
},
]
const router =createRouter({
history:createWebHashHistory(),
routes
})
export default router
3.main.js中挂载到全局
import { createApp } from 'vue'
import App from './App.vue'
import router from "./router"
const app =createApp(App)
app.use(router)
app.mount('#app')