How to reuse a child routes
#react-router
I have a route like this:
- // will show members of $id company
- // will show all members
The members route will render the same component , it just uses different parameters to
fetch
.
This is just a small sample, there are many similar route reuse cases for me.7 Replies
sensitive-blue•10mo ago
Make a common component, I usually do something like
then for typing
consider the above pseudocode, that's just an example of how to do this
afraid-scarletOP•10mo ago
I think I know what to do, thanks 🙂
conscious-sapphire•10mo ago
i believe this may be what you are looking for
https://tanstack.com/router/latest/docs/framework/react/guide/type-safety#what-if-i-dont-know-the-route-or-its-a-shared-component-and-i-cant-pass-from
if you create a shared component you can use something like
const data = useLoaderData({strict: false})
and get the loader data from the closest parent routeType Safety | TanStack Router React Docs
TanStack Router is built to be as type-safe as possible within the limits of the TypeScript compiler and runtime. This means that it's not only written in TypeScript, but that it also fully infers the...
afraid-scarletOP•10mo ago
In fact, I'm confused about using
navigate
in common components. useSearch
and useParams
can simply skip ts verification through strict
. But navigate's from is not only a ts verification issue, it also involves the correct route path.conscious-sapphire•10mo ago
Can you provide an example? useNavigate's opts.from should be optional
afraid-scarletOP•10mo ago
I tried to change my thinking. I think I might have thought too complicated before.
conscious-sapphire•10mo ago
cool did you get it worked out?