reactjs - 在 react-admin 中实现 BackButton
问题描述
我需要<BackButton />
在react-admin中实现一个,例如,当我打开show
需要能够返回该list
页面的资源的页面时。
你能指导我实现这个吗?我不熟悉 react-admin 路由机制。现在我在我的edit
表单actions
道具中使用这个组件:
const MyActions = ({ basePath, data, resource }) => (
<CardActions>
<ShowButton basePath={basePath} record={data} />
<CloneButton basePath={basePath} record={data} />
{/* Need <BackButton /> here */}
</CardActions>
);
export const BookEdit = (props) => (
<Edit actions={<MyActions />} {...props}>
<SimpleForm>
...
</SimpleForm>
</Edit>
);
解决方案
您可以使用react-router-redux
'goBack()
函数来实现这一点。
例如,您的按钮组件将如下所示:
import React, { Component } from 'react';
import { connect } from 'react-redux';
import Button from '@material-ui/core/Button';
import { goBack } from 'react-router-redux';
class BackButton extends Component {
handleClick = () => {
this.props.goBack();
};
render() {
return <Button variant="contained" color="primary" onClick={this.handleClick}>Go Back</Button>;
}
}
export default connect(null, {
goBack,
})(BackButton);
现在在你的CardActions
.
推荐阅读
- c++ - 在 Fedora 28 下使用 Eclipse CDT 中的 Clang
- r - 用 kable 或 DT 将标题固定在顶部
- javascript - 获取 thingsboard 小部件上的所有资产名称
- python - Python Graphql Django Server Mutation info.context.files 返回没有文件的空列表
- oracle - 如何描述嵌套表的结构?
- c# - C# - 如何使用反射改进代码
- python - 我想在 OS shell 中启动一个包含从 django 库导入的 python 文件
- docker - SpringBoot 控制器跨 docker poods 重定向
- c# - 如何在 .NET Core 中捕获异常并使用状态码进行响应
- google-cloud-platform - Dialogflow:在后续事件触发的意图上显示“处理”消息