Mandatory query params for same route path? #1955
-
I have this requirement where the same path behaves differently depending on the presence of a query parameter. Take the following scenario as an example:
I'm having issue declaring the first case. Registering a new router entry like Declaring it as Tried various approaches and passed through the doc but could not find a solution. Is this even possible? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
the path is just the path, it doesn't contain the query, that's why your declaration with a custom regex do not work. For this kind of scenario, using a navigation guard is the way to go: router.beforeEach((to) => {
if (to.name === 'my-route-to-check') {
// ...
}
}) There are a few extra examples in the docs. This page is also worth checking for your case. |
Beta Was this translation helpful? Give feedback.
the path is just the path, it doesn't contain the query, that's why your declaration with a custom regex do not work.
For this kind of scenario, using a navigation guard is the way to go:
There are a few extra examples in the docs. This page is also worth checking for your case.