首页 > 解决方案 > 如何在 Edit 中提供自定义重定向到 SimpleForm?

问题描述

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

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

有没有办法在 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>
);

标签: admin-on-restreact-admin

解决方案


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

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

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


推荐阅读