How to pass custom objects in route queries #1994
-
I'm trying to do something very simple. I want to be able to pass an object through I ended up doing something like this, but I really wanted to avoid doing <router-link
:to="{
name: 'route',
query: {
status: JSON.stringify(object),
},
}"
>
<span> {{ object.name }}</span>
</router-link> It looks like from this stack overflow post that it may be possible to use an object directly, but I was not able to. I also found another issue (#494) that mentioned that doing the JSON encoding is the only way to go. If this is the case, this needs to be documented as well. TLDR:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I would caution against placing stuff in the router unless you are attempting to pass the route data to the component as a prop. I saw a project using this technique and it is extremely sloppy, and hard to unit test. If you are trying to access data across the application it would be best to reach for state management. Currently they do recommend using Piñia. The testing (unit, tdd, bdd, etc...) will be much easier to read and maintain. The answer to you question for 4 is the API Not sure I am qualified to answer you question, hope it helps. |
Beta Was this translation helpful? Give feedback.
-
I think you are looking for the options |
Beta Was this translation helpful? Give feedback.
I think you are looking for the options
parseQuery
andstringifyQuery
: https://router.vuejs.org/api/interfaces/RouterOptions.html#parseQuery