import { NavBar } from 'react-vant';\nimport { useHistory } from 'react-router-dom';\n\ntype Props = {\n title?: string;\n righttext?: string;\n back?: () => void;\n};\n\nconst Cpnavbar = (props: Props) => {\n const history = useHistory();\n\n const ClickLeft = () => {\n if (props.back) {\n return props.back();\n }\n history.goBack();\n };\n\n return (\n

\n <NavBar\n title={props.title}\n leftText="返回"\n rightText={props.righttext}\n onClickLeft={ClickLeft}\n />\n
\n );\n};\n\nexport default Cpnavbar;

React 中使用 useHistory Hook 获取 history 对象并实现返回功能

原文地址: https://www.cveoy.top/t/topic/qDbD 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录