react-admin
react-admin copied to clipboard
EditBase redirects to "list" even if redirect={false} under specific circumstances
What you were expecting: Using EditBase with redirect={false} should not redirect to list.
What happened instead:
I created a modal dialog (mui). Inside the dialog I put an EditBase
component (to have a custom form) with redirect={false}
because I did not want to change route on save or close (I only wanted to close the dialog).
What happens is when I open the dialog with the id and resource correctly provided to the EditBase
component, the resource is properly fetched.
But when I close the dialog by just clicking outside the modal (I did not try saving yet), the modal is closed (that's correct) but react admin redirects to "list" of this resource (which doesn't exist because this resource is a one-to-many relationship of another resource and only visible through a custom show component of the master resource).
The way I open or close the modal is by keeping an editingId
property in a useState
hook. When I want to close the modal I set this id to null (so the edit controller is probably accepting a null
value in the id
prop).
I would expect that by merely closing the editor (not saving or anything) the redirect behavior would not be triggered at all.
Other information:
Inspecting the code in the github repo I see that useEditController
always returns redirect: DefaultRedirect
(="list") ignoring the redirect passed by the user in the props. I don't know if this intentional or if I am missing something.
** Edit **
The same behavior does not happen with CreateBase
and redirect={false}
. In that case it works as I expected. Closing the dialog does not trigger redirect on "list" route.
** Workaround **
A workaround this behavior was to conditionally render the <EditBase ... />
component only when there is an editingId
return (
<Dialog open={id!=null && id !==''} {...props}>
{editingId ? (
<EditBase
id={editingId}
resource={resource}
redirect={false}>
{children}
</EditBase>
) : null}
</Dialog>
);
This way, when I close the modal (by setting the editingId to null) the redirect to list is not triggered.
- React-admin version: 4.2.5
- React version: 18
- Browser: Chrome (Brave)
Thanks for reporting this. Please provide a sample application showing the issue by forking the following CodeSandbox (https://codesandbox.io/s/github/marmelab/react-admin/tree/master/examples/simple).
@saysmaster can you please guide here how you create list view from edit prop?
@saysmaster can you please guide here how you create list view from edit prop?
There is no list view for this particular resource, that's why I don't want EditBase to trigger redirect to list.
No news for some time, closing.