VueRouter4.x适配Vue3
程序员文章站
2022-05-10 17:14:20
...
安装路由,注意需要4.x版本
npm install vue-router -s
在src
目录下新建router\index.js
import {
createRouter,
createWebHashHistory
} from 'vue-router'
const router = createRouter({
history: createWebHashHistory(),
routes: [{
path: "/",
name: "index",
component: () => import( /* webpackChunkName: "index" */ "@/views/index/index"),
meta: {
title: "首页"
}
},
{
path: "/main",
name: "main",
component: () => import( /* webpackChunkName: "main" */ "@/views/main/main"),
meta: {
title: "主要"
}
}
]
})
export default router;
在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')
App.vue
新增
<router-view></router-view>
上一篇: 归并排序求逆序对