Skip to content

Commit

Permalink
fix: keep search params while doing background location redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarkhanzadian committed Dec 6, 2023
1 parent 9414a9b commit 6b7ce6a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/app/routes/hooks/use-background-location-redirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@ import { useLocationState } from '@app/common/hooks/use-location-state';
*/

export function useBackgroundLocationRedirect(baseUrl = RouteUrls.Home) {
const { pathname, state } = useLocation();
const { pathname, state, search } = useLocation();
const navigate = useNavigate();
const backgroundLocation = useLocationState('backgroundLocation');

useEffect(() => {
void (async () => {
if (backgroundLocation === undefined) {
return navigate(pathname, {
state: { backgroundLocation: { pathname: baseUrl }, ...state },
});
return navigate(
{ pathname, search },
{
state: { backgroundLocation: { pathname: baseUrl }, ...state },
}
);
}
return false;
})();
}, [backgroundLocation, baseUrl, navigate, pathname, state]);
}, [backgroundLocation, baseUrl, navigate, pathname, state, search]);
}

0 comments on commit 6b7ce6a

Please sign in to comment.