When I put the state value in the link prop of the react router dom, I want to use the data I put in the state when the link was executed in the moved component, but I don't know how.
When console.log(location;), I want to see the wordlist in the state value.
<Link
to={{
pathname: `/test/${wordlist[0]?.contents}`,
state: {
wordlist: wordlist,
},
}}
>
<ColorButton>test</ColorButton>
</Link>
export default function Test(props) {
const location = useLocation();
console.log(location);
return()
}
In react-router v6, state is passed as a prop in Link component:
<Link
to={`/test/${wordlist[0]?.contents}`}
state={{ wordlist }}
>
<ColorButton>test</ColorButton>
</Link>