Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirecting to create page with useRedirect try to load the edit page #6141

Closed
ThieryMichel opened this issue Apr 9, 2021 · 1 comment · Fixed by #6145
Closed

Redirecting to create page with useRedirect try to load the edit page #6141

ThieryMichel opened this issue Apr 9, 2021 · 1 comment · Fixed by #6145
Assignees
Labels

Comments

@ThieryMichel
Copy link
Contributor

What you were expecting:
I needed to pass some custom query parameter to the create page.
For that I used useRedirect with a simple Button, and so added the needed params.
It worked until I changed version from 3.12.0 to 3.14.2.

What happened instead:
With the new version clicking on the button the page attempt to load and it display a Element does not exists notification and return on the list page.
In the network tab, I see that react-admin attempt to fetch a resource with the id create.
Seems like react-admin believe I want to edit.

Steps to reproduce:
Simply create a button to redirect to a creation page using useRedirect.

const CustomCreateButton = () => {
  const redirect = useRedirect();
  const onClick = () => redirect("posts/create?foo=bar");
  return (
    <Button color="primary" variant="outlined" onClick={onClick}>
      redirect to create
    </Button>
  );
};

Related code:

Here is a code sand box
https://codesandbox.io/s/jovial-glitter-of0yi?file=/src/posts/PostList.tsx

Simply go to the list of post and click on the redirect to create at the top.

Other information:
It is possible to avoid the issue by using a Link instead of useRedirect.

Environment

  • React-admin version: 3.14.2
  • Last version that did not exhibit the issue (if applicable): 3.12.0
  • React version: 17.0.1
  • Browser: chrome
  • Stack trace (in case of a JS error):
@djhi
Copy link
Collaborator

djhi commented Apr 9, 2021

So that's because the Link component call createLocation from the history package which returns a Location object.

To fix it, resolveToRedirect should return a Location object as well but this might be breaking change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants