Missing param for named route: Expected “x” to be defined

断了今生、忘了曾经 提交于 2020-05-14 18:27:13

问题


Whether I do this

Vue.router.push({ path: '/beats/catalog/1' }) 

or this

Vue.router.push({ name: 'BeatsCatalog', params: { page: 1 } })

I get the same result: [vue-router] missing param for named route "BeatsCatalog": Expected "page" to be defined.

Router:

{
        path: '/beats',
        components: {
            navbar: Navbar,
            default: { template: `<router-view/>` }
        },
        children: [{
                name: 'BeatsCatalog',
                path: 'catalog/:page',
                components: {
                    default: () => import('@/views/BeatsCatalog')
                },
                props: { default: true }
            },
            {
                path: 'upload',
                name: 'BeatsUpload',
                components: {
                    default: () => import('@/views/BeatsUpload')
                }
            },
        ],
        meta: { requiresAuth: true }
    }

What's causing the issue? I see nothing wrong with my setup, I'm doing everything like in the documentation. Thanks.


回答1:


@Giacoma, In your data property on the component BeatsCatalog the page is undefined when initally loaded. Hence you get the error.

So to solve this wrap your router-link in v-if.

Reference for the same error with better explaination is here:

https://github.com/vuejs/vue-router/issues/986



来源:https://stackoverflow.com/questions/47897542/missing-param-for-named-route-expected-x-to-be-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!