Merge pull request #4790 from thornbill/redirect-with-search

This commit is contained in:
Bill Thornton 2023-09-20 09:04:25 -04:00 committed by GitHub
commit dbd068b3e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,17 +1,28 @@
import React from 'react'; import React from 'react';
import { Navigate, Route } from 'react-router-dom'; import { Navigate, Route, useLocation } from 'react-router-dom';
export interface Redirect { export interface Redirect {
from: string from: string
to: string to: string
} }
const RedirectWithSearch = ({ to }: { to: string }) => {
const { search } = useLocation();
return (
<Navigate
replace
to={`${to}${search}`}
/>
);
};
export function toRedirectRoute({ from, to }: Redirect) { export function toRedirectRoute({ from, to }: Redirect) {
return ( return (
<Route <Route
key={from} key={from}
path={from} path={from}
element={<Navigate replace to={to} />} element={<RedirectWithSearch to={to} />}
/> />
); );
} }