vue3中的vue-router

下载

npm i -S vue-router@4

新建页面

vue3中的vue-router_第1张图片vue3中的vue-router_第2张图片vue3中的vue-router_第3张图片

import { createRouter, createWebHistory } from 'vue-router'


const routes = [
    {
        path: '/a',
        name: 'A',
        component: () => import('@/views/A/index.vue')
    },
    {
        path: '/b',
        name: 'B',
        component: () => import('@/views/B/index.vue'),
        beforeEnter: (to, from, next) => {
            if (true) {
                next()
            } else {
                next("/login")
            }
        }
    },
    {
        path: '/login',
        name: 'login',
        component: () => import('@/views/login/index.vue'),
    }
]

const router = createRouter({
    history: createWebHistory(),  //history
    routes
})

export default router

你可能感兴趣的:(vue3,vue.js)