我已经尝试从useRoutes
的hookrouter
从一页导航到另一页,但是效果很好。我想通过该路线传递一些物体。我应该如何传递物体?我已经阅读了hookrouter
GitHub页面,但仍然没有理解。我尝试过navigate("/home",true,{name:"batman"});
,但没有帮助。我该怎么办?
您可以在react-router-dom中使用链接组件。
import { Link } from 'react-router-dom';
<Link to={`home/${obj.name}`}> Click here </Link>
如果您使用按钮作为路由事件触发器:
import { Button } from '@material-ui/core';
import { Link } from 'react-router-dom';
<Button
...
component={Link}
to={{
pathname: `yourRoutePath`,
// write your custom state below
state: {
otherCustomState: value,
// sample below
prevPath: history.location.pathname,
}
}}
>
next page
</Button>
用法
history.location.state.yourCustomState