欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

VueRouter4.x适配Vue3

程序员文章站 2022-05-10 17:14:20
...

安装路由,注意需要4.x版本

npm install vue-router -s

src目录下新建router\index.js
VueRouter4.x适配Vue3

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>
相关标签: Module