React-router: [v6] setParams from useSearchParams ignores current location

Created on 17 May 2020  路  5Comments  路  Source: ReactTraining/react-router

Version

6.0.0-alpha.5

Test Case

https://codesandbox.io/s/react-router-1w91e

Steps to reproduce

call setParams() in a Container with an outlet.

Expected Behavior

search params are appended to the current path

Actual Behavior

search params replace the current path.

I assume this is because "*" doesn't actually pop any route segments - I'm struggling to find v5 docs that warn about this however.

stale

Most helpful comment

I am seeing this issue too. Pretty sure it is a bug...

Related to how navigate doesn't work on dynamic routes like foo/*.

All 5 comments

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
You can add the fresh label to prevent me from taking any action.

I am seeing this issue too. Pretty sure it is a bug...

Related to how navigate doesn't work on dynamic routes like foo/*.

@mjackson @ryanflorence can we reopen this issue?

EDIT: seeing this issue on v6.0.0-beta.0

I'm also seeing this unfortunately

So the work around is just doing

const location = useLocation();
...
navigate({
      pathname: location.pathname,
      search: "?" + createSearchParams({ ...newParams }),
    });

The issue is that useSearchParams tries to navigate to the parent path (?) which breaks children paths
https://github.com/ReactTraining/react-router/blob/dev/packages/react-router-dom/index.tsx#L418

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wzup picture wzup  路  3Comments

ackvf picture ackvf  路  3Comments

maier-stefan picture maier-stefan  路  3Comments

jzimmek picture jzimmek  路  3Comments

andrewpillar picture andrewpillar  路  3Comments