I'm working on a project based on react. I'm trying to pass some stuff through the to of the Link component but this does not work. The previous page return me always "/home" and data return me "undefined". Someone can help me with this code? Maybe i wrote something in a bad way.
Here the Link code
<Link
to={{
pathname: "/home/newtask",
state: {
previousPage: window.location.pathname,
data: "event",
},
}}
className="btn"
style={{
textDecoration: "inherit",
backgroundColor: "#c5fdc8",
width: "100px",
cursor: isButtonDisabled
? "not-allowed"
: "pointer",
}}
>
New Event
</Link>
Here how i recall it form the newtask page
const location = useLocation();
const previousPage = location.state?.previousPage || "/home";
console.log(previousPage);
console.log(location.state?.data);
I will appreciate very much an help on this.