I am trying to pass props from NavLink
in react-router-dom to another component (component that router routes to). The code is:
<HashRouter>
<div className="navigation">
<NavLink to="/" className="navigation-link">Home</NavLink>
<NavLink quizid="60fcf0f3b55bab18d841e4c3" className="navigation-link"
to={{
pathname:'/thisquiz',
state: "60fcf0f3b55bab18d841e4c3"
}} exact>Quiz</NavLink>
</div>
<div>
<Route default exact path="/" component={Home}></Route>
<Route path="/thisquiz" component={Quiz}></Route>
</div>
</HashRouter>
In the Quiz
component:
let location = useLocation();
console.log("The state is "+location.state);
The output shows The state is undefined
. Please help.