T
TanStack2y ago
other-emerald

Show optional modal based on route without loading additional data

I have the following urls /overview and /overview/$singleID where the main page is a table of content and if you click on something I want to show a modal. Right now I've solved this with an <Outlet /> and it works great. But since I can't pass data down to the Outlet I need to load data twice. I could obviously solve this using a context but this feels overkill. What's the best way to have two routes load the same view? I could control the modal based on if $singleID is set or not. But how would I then have both /overview and /overview/$singleID load the same component?
4 Replies
magic-amber
magic-amber2y ago
If you're using tanstack-query, you could just get the data you need from the cache. Otherwise I think you can't do it properly without a context, sadly.
other-emerald
other-emeraldOP2y ago
Yeah sorry, should have mentioned how I fetch data. I'm using Apollo. So cache would solve the problem as well. I was mostly curious about if there were a better way of doing it.
magic-amber
magic-amber2y ago
I had the same "problem" and search for a solution but didn't found one. I don't think it exists a better approach
rising-crimson
rising-crimson2y ago
do you have a minimal example? I don't get the setup fully

Did you find this page helpful?