[英]react router getting the right display page when click button
I have a question regrading to react.我有一个问题需要重新评分。 I have a IconButton (Material UI) I want to click this button and it will redirect to the specific help page.我有一个 IconButton (Material UI) 我想点击这个按钮,它会重定向到特定的帮助页面。
For example:例如:
I am stuck, I am not sure how to implement the button onClick function to redirect to the right support page.我被卡住了,我不确定如何实现按钮 onClick function 以重定向到正确的支持页面。 I am thinking using react-router, I have did some research we can use 'params' and 'history' parameters from the props?我正在考虑使用 react-router,我做了一些研究,我们可以使用道具中的“参数”和“历史”参数? Thank you谢谢
Please give me some good advice and right direction thank you.请给我一些好的建议和正确的方向谢谢。
import { useLocation, useHistory } from "react-router-dom";
export default function App() {
const history = useHistory();
const { pathname } = useLocation();
return (
<div className="App">
<button onClick={() => history.push(`${pathname}/support`)}>
support page
</button>
</div>
);
}
localhost:3000/education.本地主机:3000/教育。 If you use history.push("/support"), It redirects to localhost:3000/support.如果你使用 history.push("/support"),它会重定向到 localhost:3000/support。 But If you use history.push("support"), It redirects to localhost:3000/education/support但是如果你使用history.push("support"),它会重定向到localhost:3000/education/support
https://reactrouter.com/web/api/Hooks https://reactrouter.com/web/api/Hooks
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.