1.安装
npm i vue-router
2.index.js
import { createRouter, createWebHashHistory } from 'vue-router'
const routes = [
{
path:'/',
component: () => import('../views/Main.vue'),
children: [
{
path: '/',
name: 'home',
component: () => import('../views/home/Home.vue')
}
]
}
]
const router = createRouter({
history:createWebHashHistory(),
routes
})
export default router
3. main.js
import App from './App.vue'
import router from './router/index.js'
app.use(router)
4.APP.vue和Main.vue中 写路由出口
<router-view></router-view>