首页 > 解决方案 > Uncaught TypeError:

问题描述

I'm working on a web app with Vue.js and I get this error when I set up my routing in my route.js file, I don't see where is the problem. Is there someone that can help with this issue thanks?

        router.js?41cb:8 Uncaught TypeError: Object(...) is not a function
        at eval (router.js?41cb:8)
        at Module../src/router.js (app.js:1349)
        at __webpack_require__ (app.js:849)
        at fn (app.js:151)
        at eval (main.js:11)
        at Module../src/main.js (app.js:1337)
        at __webpack_require__ (app.js:849)
        at fn (app.js:151)
        at Object.1 (app.js:1362)
        at __webpack_require__ (app.js:849)
    eval @ router.js?41cb:8
    ./src/router.js @ app.js:1349
    __webpack_require__ @ app.js:849
    

Here is my code below.

        import {createRouter, createWebHistory} from 'vue-router';
        import MusicApp from './components/home/MusicApp.vue';
        import PageNotFound from './components/PageNotFound.vue';
        
        const router = createRouter({
        history: createWebHistory(),
             routes: [
                 {path: '/', redirect: '/home'},
                 {path: '/home', component: MusicApp},
                 {path: '/:notFound(.*)', component: PageNotFound}
            ],
        });
        
        export default router; 

标签: functionvue.jsroutesvue-router

解决方案


看起来您正在使用旧版本的 vue-router 和 Vue3。Vue3 仅适用于 alpha 版本。要安装 alpha 版本,请运行: npm install vue-router@next


推荐阅读