How to pass an object as props with vue router?

It can work by using props’s Function mode and params

Vue 2 demo: https://jsfiddle.net/hacg6ody/

when adding routes, use props’s Function mode so that it has a default property user and it will add route.params as props.

{
    path: '/create',
    name: 'create',
    component: CreateComponent,
    props: (route) => ({
        user: userData,
        ...route.params
    })
}

params passed in push will automatically be added to props.

self.$router.push({
    name: 'create',
    params: {
        otherProp: {
            "a": "b"
        }
    }
})

Leave a Comment