VUE报错:Error in render function: “TypeError: Cannot read property ‘matched‘ of undefined“

Error in render function: "TypeError: Cannot read property 'matched' of undefined"​

This error is usually caused by using a property or method of the $router object when the $route object does not exist. Please ensure that the $route and $router objects are fully created and initialized when using them.

The parameters when instantiating VueRouter can be abbreviated as routes, which means routes:routes. But it should be noted that "routes:routes" means that the attribute name is routes and the value is routes. In this case (attribute names and values ​​are both routes), the abbreviation can be used. However, do not mistakenly think that the abbreviation routes is the variable name (array name) of the route. If your array name is myroutes, then the correct way to write it is routes:myroutes.

The following is a correct example:

var myroutes= [
        {path:"/",component:Hello},
        {path:"/h",component:Hello},
        {path:"/w",component:World}
    ];

const myroute = new VueRouter({ 

    routes:myroutes

});

On the official website, abbreviations are also used when instantiating vue objects, such as:

const app = new Vue({  

router

}).$mount('#app')

Router is equivalent to: router:router, also because the variable name is the same as the attribute name . If your routing instance name is not router, do not omit it.

as follows:

import {r} from "./router/index.js";//路由的配置
//使用第三方组件必须用use函数。
Vue.use(VueRouter);

new Vue({

    el:"#app",
    router:r,
    render:(h)=>{
        return h(App)
    }
});

Guess you like

Origin blog.csdn.net/weixin_40381947/article/details/131380340
Recommended