Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ahoi's avatar
Level 5

Missing parameter for vue-router when using beforeRouteEnter

Hello everybody,

I am using the vue-router to navigate through my SPA.

This is my router:

export default [{
    path: '/user',
    component: Layout2,
    meta: {
        requiresAuth: true
    },
    children: [
        {
            path: '/',
            name: 'user',
            component: () => /* webpackChunkName: "view-[request]" */ import('@/components/Index'),
            meta: {
                requiresAuth: true
            },
        },
        {
            path: ':id',
            name: 'user.view',
            component: () => /* webpackChunkName: "view-[request]" */ import('@/components/View'),
            meta: {
                requiresAuth: true
            },
        },
        {
            path: ':id/edit',
            name: 'user.edit',
            component: () => /* webpackChunkName: "view-[request]" */ import('@/components/Edit'),
            meta: {
                requiresAuth: true
            },
        },
    ]
}]

Now I added this:

<b-btn variant="primary" size="sm" :to="{ name: 'user.edit', params: { id: user.id }}">Edit</b-btn>

It's a part of vue-bootstrap.

I also make use of beforeRouteEnter:

data: () => ({
        user: {},
    }),
    beforeRouteEnter (to, _from, next) {
        axios
        .get ('/api/user/' + to.params.id).then ((resp) => {
            next ((vm) => {
                vm.user = resp.data.data;
            });
        });
    },

Alright - this seems to work - but I am receiving this warning:

[vue-router] missing param for named route "user.edit": Expected "id" to be defined

If I dump user.id in my component, 1 is being returned.

So now I am wondering: The component shouldn't be rendered if beforeRouteEnter is not finished, right? But why do I get this warning?

0 likes
3 replies
bobbybouwmann's avatar

Mmh everything seems to look correct. Maybe you can figure out what is being called first by doing some more console.logs around the code

I was wondering why would you want to do the user call everything you do a user action? Why not cache the user on first fetch so you can reuse that state. You can use vuex to manage a state if you wish.

ahoi's avatar
Level 5

Hi @bobbybouwmann

first of all: Thanks for your reply.

I am using vuex to store the data of the logged-in user. The user the edit link is placed for is a user the authenticated user is managing.

Please or to participate in this conversation.