如何在Edit中为SimpleForm提供自定义重定向?

时间:2018-06-08 06:55:32

标签: admin-on-rest react-admin

编辑后,我按照约定重定向列表。

但是,我需要在列表网址中提供其他参数。

有没有办法去欺骗"在SimpleForm / Edit上自定义重定向?

以下是我的代码的相关部分:

const ProviderUserEditActions = ({ basePath, data }) => {
  if (! data) return null
  return (
    <CardActions style={cardActionStyle}>
        <ListButton basePath={basePath+'?'+queryString.stringify({providerId:data.providerId, providerName:data.providerName})} />
        <RefreshButton />
    </CardActions>
  );
}

export const ProviderUserEdit = (props) => (
    <Edit actions={<ProviderUserEditActions/>} title={<ProviderUserEditTitle />} {...props}>
        {/*redirect=false will cause the loosing of the URL parameters :(
          but this is the "least worst", because otherwise it would redirect to
          'list' but without URL parameters it will completely crash...
          we hope that someday we will be able to provide our own redirect
          function
          */}
        <SimpleForm redirect={false}>
            <TextInput source="name" />
            <TextInput source="email" />
            <TextInput source="phone" />
            <BooleanInput source="activated" />
        </SimpleForm>
    </Edit>
);

1 个答案:

答案 0 :(得分:1)

没有记录,因此我将创建一个问题,将其添加到文档中,但您可以将路径指定为redirect道具:

<SimpleForm redirect={`/list?myParam=${myValue}`}>

请参阅:https://github.com/marmelab/react-admin/blob/master/packages/ra-core/src/util/resolveRedirectTo.js