TanStackT
TanStack4mo ago
2 replies
endless-jade

Best way to do dynamic layouts?

How can I get a parent layout component to dynamically render content based on what child route it is currently on?

For example, if I have nested routes like /fruit/banana and /fruit/apple, how does the parent component know to display a banana or an apple image in a shared sidebar, while the child component renders the corresponding details? The best way I can think of is to just use useLocation to get the path and use the path in a switch statement to return the right displays. Is there a better way to this? I was wondering if there was some design pattern to resolve two separate "outlets" on the same path.
Was this page helpful?