How to globally capture matched params before / after route change? #128
-
Is there a way to listen for route changes and do something with the matched information like search / params? Vue router has a In my case, I'm trying to implement a flow that subscribes to a websocket based on the ':id' of something in the URL, but there are multiple routes / components that use this ':id', so it makes sense to put this logic at the top-level of the router. I thought the Root component used as a child of the Router component in some of the examples might be able to do that, but all hooks return information resolved from root '/', which makes sense. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
You could try using a wildcard with useMatchRoute from the root. Or you could just listen to useRouter().state.matches, and use the params from the last match (it would have all of them) |
Beta Was this translation helpful? Give feedback.
-
When I say listen, I mean useEffect and friends |
Beta Was this translation helpful? Give feedback.
-
useEffect with useRouter().state.matches works like a charm. thanks! |
Beta Was this translation helpful? Give feedback.
You could try using a wildcard with useMatchRoute from the root. Or you could just listen to useRouter().state.matches, and use the params from the last match (it would have all of them)