Cannot use ‘in‘ operator to search for ‘path‘ in undefined

在搭建vue3.0项目的时候,配置路由这一块,变化还很多的,
遇到这个错,找半天也没发现,最后才发现在定义路由模式的时候,
之前的做法是mode属性来定义,vue3.x废除了mode改用history ,而从vue-router 中对应的模式api实现,

createWebHistory -> history 它就对应vue2.x版本的history模式

import {
    
     createRouter, createWebHistory } from "vue-router";
import Layout from "@/pages/Layout.vue";

const routes = [
    {
    
    
        path: '/',
        component: Layout
    }
]
const router = createRouter({
    
    
    history: createWebHistory(),//这是正确的;错误提示:不要当成变量使用
    routes
})
export default router

猜你喜欢

转载自blog.csdn.net/sxs7970/article/details/120288565