how can I match a route with same component and not rerender?
I want to render my
/login and /register pages with the same component.
the router should render the same component but only change disabled properties on input fields and toggle this className on an overlay div.
simple recreation:
9 Replies
tame-yellow•13mo ago
check
useMatchesrival-blackOP•13mo ago
heres a codesandbox, got it to work.
I handle everything in the
_auth.lazy.tsx component, which is kinda weird, but it works.
LMK if you got a better solution
https://codesandbox.io/p/github/zdenkolini/tanstack-router-single-route-auth/main?import=truetame-yellow•13mo ago
just a hint, you don't need to use
lazy anymore with automatic codesplittingrival-blackOP•13mo ago
other than that, you wouldn't change anything?
tame-yellow•13mo ago
i personally would pass the route I am on via a prop into the component
if it is just two routes, why complicate things
rival-blackOP•13mo ago
so if I understand this right, just create a child component that takes in the isLoginRoute boolean as a prop and keep the router setup regarding route definitions and isLoginRoute boolean derivation logic?
IMO there should be an example or functionality of defining possible options for url parameters
for example
/auth/:page(login|register) to register 2 routes that render the same componentrival-blackOP•13mo ago
here is an example of such a route for react router v5
https://v5.reactrouter.com/web/api/generatePath
rival-blackOP•13mo ago
via the current docs, I think this is possible to achieve with a loader that will
throw notFound() if the url parameter is not one of the 2 :pages.
I'll update the sandbox and get back to you to showcase what I meantame-yellow•13mo ago
contributions are always welcome!