T
TanStack12mo ago
sunny-green

Can I matchRoute on a wildcard path?

I want this kind of logic:
const isAuthRoute = !!matchRoute({ to: "/auth/*" }); // wildcard not allowed
if (!isAuthRoute) {
// ...
}
const isAuthRoute = !!matchRoute({ to: "/auth/*" }); // wildcard not allowed
if (!isAuthRoute) {
// ...
}
Where I can choose to do something when the user is at any path under /auth . I can't use { to: "/auth", fuzzy: true" } because /auth on its own is not a valid selectable route in my app.
3 Replies
absent-sapphire
absent-sapphire12mo ago
you could add a route.tsx into the auth folder or you could add a pathless / layout route around that. can you please provide some more information about your use case? so we can find the best solution
sunny-green
sunny-greenOP12mo ago
I have a sign in button in my nav, which when clicked navigates to /auth/login?from= where the from param is used to navigate back to wherever it was called from. If the user clicks the login button whilst in the login journey, it will try to navigate them back to that step in the journey after it's completed, which is kind of weird behaviour. There might be a better way, but for now I'd like to just conditionally hide the login button when the user is on any part of the login journey, which could be either /auth/login or /auth/verify, without manually checking for each one.
absent-sapphire
absent-sapphire12mo ago
so is adding the route.tsx to the auth folder an option?

Did you find this page helpful?