I went through this vue-router@4.05 object params which is somewhat related. There is a mention of this https://github.com/vuejs/vue-router-next/issues/494 in that thread, but I am still confused.
I am also trying to pass some data using the :to attribute of the router link component. I have made two pens to showcase the issue:
Pen 1 passes an object that is defined within the routes definition - successfully.
Pen 2 is trying to pass a dynamic object and instead of the actual object it gets a string with [Object object] as described in the github issue.
console output:
[Vue warn]: Invalid prop: type check failed for prop "repository". Expected Object, got String with >value "[object Object]". at <Repository repository="[object Object]" onVnodeUnmounted=fn ref=Ref > at at at
So, if I get this straight, ultimately you cant pass a dynamic object cos it's parsed, but you can pass a static object?
I have tried with props: true and everything, I am trying the function mode solution as a more complex example
snippets:
<router-link :to="{ name: 'Home' }">Home</router-link>
<router-view />
<router-link
:to="{
name: 'Repository',
params: { repository: { one: '1', two: '2' } },
}">click me</router-link>
v1
const routes: Array<RouteRecordRaw> = [
{
path: "/",
name: "Home",
component: Home
},
{
path: "/repo/",
name: "Repository",
component: () => import("../components/Repository.vue"),
props: (route) => {
console.log("entered route");
console.log(route);
return { ...route.params, repository: { one: "1", two: "2" } };
}
}];
v2
const routes: Array<RouteRecordRaw> = [
{
path: "/",
name: "Home",
component: Home
},
{
path: "/repo/",
name: "Repository",
component: () => import("../components/Repository.vue"),
props: (route) => {
console.log("entered route");
console.log(route);
return { ...route.params };
}
}];