我对 React 世界相对较新,正在努力找到一种方法将 IconButton 加载到 AppBar 的工具栏(从 Material UI(。
假设我在页面 A 上,并且喜欢有两个特定于页面 A 的 IconButton,当我到达页面 B 时,我喜欢加载特定于页面 B 的工具栏按钮。
我创建了一个代码沙箱项目,以便任何人都可以更轻松地提供帮助。 https://codesandbox.io/s/material-ui--react-admin-1qc5x
我感谢任何帮助,指导等。
您可以通过多种方式实现此目的:
-
Redux:您可以使用
react-redux
并创建一个store
,您可以在其中存储您的current_page
值(SPA 的最佳实践(并访问页面值static getDerivedStateFromProps(props, state){ //your code here }
- 基于路线(
react-router
( - [我所做的]基于
URL params
,就像您正在做的那样history.push
因此更容易从您的URL中提取参数并基于此呈现您的工具栏图标。
我的代码参考:https://codesandbox.io/s/material-ui--react-admin-nxh7m