You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
useSearchParam('redirect') from react-use returns null when redirected via next.js middleware after a router.push() navigation, despite the redirect parameter being present in the URL.
Steps to reproduce it and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have extra dependencies other than react-use. Paste the link to your JSFiddle or CodeSandbox example below:
Set up a Next.js application with protected routes and authentication middleware.
Create a form submission handler that uses router.push to navigate to a protected route:
Implement middleware that redirects to login for protected routes:
// src/middleware.tsif(isProtectedPath&&!accessToken){constloginUrl=newURL('/auth/login',request.url)// Add the current path as a redirect parameterloginUrl.searchParams.set('redirect',`${request.nextUrl.pathname}?${request.nextUrl.searchParams}`)returnNextResponse.redirect(loginUrl)}
On the login page, attempt to access the redirect parameter using useSearchParam and observer that useSearchParam('redirect') returns null.
Note that this does not happen when pasting the URL directly into the address bar or clicking an anchor tag.
What is the expected behavior?
useSearchParam('redirect') should return the redirect parameter value from the URL, as useSearchParams.get('redirect') from next/navigation does.
A little about versions:
macOS 15.2 24C101 arm64
Google Chrome Version 133.0.6905.0 (Official Build) dev (arm64)
react 18.3.1
react-use 17.5.1
Did this worked in the previous package version?
🤷
I spent some time wondering why my redirect from my login page wasn't working and ended up testing with next/navigation for sanity and found I was sane.
The text was updated successfully, but these errors were encountered:
What is the current behavior?
useSearchParam('redirect')
fromreact-use
returns null when redirected vianext.js
middleware after arouter.push()
navigation, despite the redirect parameter being present in the URL.Steps to reproduce it and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have extra dependencies other than
react-use
. Paste the link to your JSFiddle or CodeSandbox example below:router.push
to navigate to a protected route:useSearchParam
and observer thatuseSearchParam('redirect')
returns null.Note that this does not happen when pasting the URL directly into the address bar or clicking an anchor tag.
What is the expected behavior?
useSearchParam('redirect')
should return the redirect parameter value from the URL, asuseSearchParams.get('redirect')
fromnext/navigation
does.A little about versions:
react
18.3.1react-use
17.5.1🤷
I spent some time wondering why my redirect from my login page wasn't working and ended up testing with
next/navigation
for sanity and found I was sane.The text was updated successfully, but these errors were encountered: