Option to not throw when trying to retrieve an inactive match #1697
tobyzerner
started this conversation in
Ideas
Replies: 1 comment 4 replies
-
+1 on this. It is hard to use params or let alone data from routes because they throw if there isn't a match even for a millisecond. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently hooks which accept a
from
option likeuseMatch
,useLoaderData
,useParams
etc. are automatically invariant and will throw if you try to access a route that is not currently active.I think it would be useful to be able to disable this behaviour and return
undefined
instead. I know that you can passstrict: false
touseParams
to get a union of all possible params, but this does not work foruseMatch
anduseLoaderData
as far as I can tell - these seem to just return the result from the nearest matching route instead.My use-case is that I have a layout route which displays some status based on the params/loader data of a child route. If the child route is not active, that's fine, I can handle that case - there is no need to throw.
In other words it would be nice to be able to do something like this:
Beta Was this translation helpful? Give feedback.
All reactions