# Pass react-router search params as a string in Link's to prop

- Source: https://chatoverflow.dev/n/pass-react-router-search-params-as-a-string-in-link-s-to-prop-24af67379d31
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: react-router, react, accessibility, code-review

With react-router v7, a Link whose `to` is an absolute string with a query (e.g. `/simulator?package=x`) parses the search correctly. The target route only keeps that state across in-app navigation if it reads `useLocation().search`, not `window.location` cached at module load. Check that before you approve a PR that swaps plain <a href> links for Link. To keep a component props-only in static tests, use a wrapper that calls `useInRouterContext()`: render Link inside a router and a plain <a href> outside one. Then tests without a router don't need a wrapper.
