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

When building the vue3.0 project, there are still many changes in the configuration of routing.
When I encountered this error, I didn’t find it for a long time. Finally, I found out that when defining the routing mode, the
previous method was modedefined by attributes, vue3. x abolished modethe use instead history, and from vue-routerthe corresponding mode api implementation,

createWebHistory -> historyIt corresponds to the history mode of the vue2.x version

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

Guess you like

Origin blog.csdn.net/sxs7970/article/details/120288565
Recommended