I am using react-router-dom v6.4 and I am wondering if I can do something. I want to pass data to another route when I redirect.
I know that in the previous version I can use the state prop:
<Redirect
to={{
pathname: "/login",
state: { referrer: currentLocation }
}}
/>
However, using redirect() that doesn't work:
import { Form, redirect } from "react-router-dom";
export function action() {
return redirect("/home", { state: { value: 5 } });
}
export default function Blog() {
return (
<Form method="post">
<button>Submit</button>
</Form>
);
}
import { useLocation } from "react-router-dom";
export default function Home() {
const location = useLocation();
console.log(location.state.value);
return <div>Home</div>;
}
Is there a way to send data when redirecting?