Skip to content

Commit

Permalink
Merge pull request #4790 from thornbill/redirect-with-search
Browse files Browse the repository at this point in the history
  • Loading branch information
thornbill authored Sep 20, 2023
2 parents 585137c + 399157b commit dbd068b
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 dbd068b

Please sign in to comment.