Split screen routes
What is the preffered way to create an overview screen of lets say 'events' and a detail screen for said event that shows on the right of the overview
when on route
/events i want the whole page to show a list of the events.
But navigating to an events goes to events/$eventId but is shown next to the overview.
what i did now is this folder structure
Problem with this approach for me is im using useParams('') inside the table since this url is has a param inside i want to use.
The actual route is clients/$clientId/events so i want to fetch all events from that client.
What i do in table is
const params = useParams('/clients/$clientId/events') but this throws an error when on /events/$eventId
Invariant failed: Could not find an active match from "/clients/$clientId/events/"
Is there an easier way to get this sort of layout?16 Replies
sunny-green•6mo ago
move the table into /events/route.tsx
metropolitan-bronzeOP•6mo ago
Thought of that as well, didnt test it yet but what should i add in index.tsx? thats just an empty file than?
sunny-green•6mo ago
you wouldn't need that then.
unless you need different content on the index view
metropolitan-bronzeOP•6mo ago
hm another issue, i also have another route where i don't want this 😛
maybe im just going for a shared component with props i need to pass in unless theres a better way
sunny-green•6mo ago
if you can provide a minimal example based on one of the Stackblitz examples i can have another look
metropolitan-bronzeOP•6mo ago
Andre de Waard
StackBlitz
Router Basic File Based Example (duplicated) - StackBlitz
Run official live example code for Router Basic File Based, created by Tanstack on StackBlitz
metropolitan-bronzeOP•6mo ago
a reading this https://tanstack.com/router/latest/docs/framework/react/api/router/useParamsHook gave me the idea that
useParams should work on child routes and gave me the idea that i was doing something wrong (because its a child route)
the fix was to acually use remove the last / since that is the index route const params = useParams({ from: '/$clientId/tasks' });useParams hook | TanStack Router React Docs
The useParams method returns all of the path parameters that were parsed for the closest match and all of its parent matches. useParams options The useParams hook accepts an optional options object. o...
sunny-green•6mo ago
yep
you can supply a parent that has the param
metropolitan-bronzeOP•6mo ago
does the example makes sense to you or am i doing something really weird?
sunny-green•6mo ago
you could also just pass on the path param as a react prop to the component
metropolitan-bronzeOP•6mo ago
yes indeed but it will lose the type hinting inside the actual component. its like using
useParams({ strict: false }) which makes clientId optionalsunny-green•6mo ago
why?
metropolitan-bronzeOP•6mo ago
This is what you meant?
sunny-green•6mo ago
no I meant passing the actual param value
metropolitan-bronzeOP•6mo ago
o you mean the clientId like so
sunny-green•6mo ago
yes