Pass disposable data through route navigation (looking for alternative to deprecated route.params
)
#2010
Unanswered
frederikheld
asked this question in
Help and Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey everyone,
I just stumbled across the issue that
route.params
is empty in the view that was routed to. After some research I found this: https://github.com/vuejs/router/blob/main/packages/router/CHANGELOG.md#important-noteI totally understand the reasoning behind this IF you want to preserve your params. The thing is that I don't want to preserve them.
My use case is as follows: User navigates to
/groups/:id
with an invalid id. After the database lookup returned no entry, the user is being routed to/groups
and a snackbar should appear that tells them "This group does not exist".In the past I solved this by passing the error message as param which was not preserved on purpose because this message should not appear again if the user refreshes the browser in
/groups
.The only thing I came up with is storing the message somewhere in pinia but then I would need to import the store in both views, which feels a bit too much effort for just passing a simple disposable piece of data that is only relevant in the context of a routing action.
I also tried using
state
as it is recommended in the above changelog but I did not figure out how to read it in the target view,route.state
isundefined
.What alternative to the deprecated
route.params
that allows me to attach one-time data to a programmatic routing action would you recommend?P. S.:
params
is indeed the wrong term for what I'm looking for as params are a defined part of an url. So it makes sense that it was removed. But I think there should be a mechanic that allows to pass disposable data, whatever it would be named.Edit: I figured out how to access
route.state
from the target: it is available inhistory.state
. Odd, but okay. Unfortunately it is not the solution I am looking for as this information is being preserved through a browser refresh.Beta Was this translation helpful? Give feedback.
All reactions