Skip to content

Commit

Permalink
Add search params to redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
thornbill committed Sep 20, 2023
1 parent 055a500 commit 399157b
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/components/router/Redirect.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
import React from 'react';
import { Navigate, Route } from 'react-router-dom';
import { Navigate, Route, useLocation } from 'react-router-dom';

export interface Redirect {
from: string
to: string
}

const RedirectWithSearch = ({ to }: { to: string }) => {
const { search } = useLocation();

return (
<Navigate
replace
to={`${to}${search}`}
/>
);
};

export function toRedirectRoute({ from, to }: Redirect) {
return (
<Route
key={from}
path={from}
element={<Navigate replace to={to} />}
element={<RedirectWithSearch to={to} />}
/>
);
}

0 comments on commit 399157b

Please sign in to comment.