Parent route query params disappear when visiting child route #8179
-
SummaryI have a Parent route and I would like to keep the query params from disappearing when viewing/visiting a Child route Outlet component (see video) CleanShot_2023-11-25_at_15.48.39.mp4Stackblitz playground: https://stackblitz.com/edit/remix-run-remix-uvugih?file=app%2Froutes%2Fparent.child.tsx Current experience
Desired experience
Maybe I'm just approaching things wrong 😅 but is there a suggested method to keep the query params of a parent route from disappearing when visiting a child route? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
you need do it manually. <Link to={`./child?${query}`} |
Beta Was this translation helpful? Give feedback.
-
@kiliman How to do the same with navigate() in my case parent with few search params If i click add item i need to maintain source_id can i do like below or any other suggested method available? |
Beta Was this translation helpful? Give feedback.
That's not how URLs and query/search params work. The search params need to be at the end of the path:
/parent/child123?q=foobar
The parent route can still access them, since they apply to the entire route, not just a single route segment.
You can create a custom
<Link>
component that always preserves the search params.