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

Invalid redirect with callback to absolute URI #10489

Open
fatal10110 opened this issue Feb 1, 2025 · 1 comment
Open

Invalid redirect with callback to absolute URI #10489

fatal10110 opened this issue Feb 1, 2025 · 1 comment

Comments

@fatal10110
Copy link

fatal10110 commented Feb 1, 2025

What you were expecting:
Im using custom routes, passing redirect property to Create component

<Create
      redirect={(resource, id, data) => `/resourceA/<raId1>/resourceB/<rbId2>/resourceC/${id}`}
      mutationOptions={{ meta: { ... } }}
      resource="resourceC"
    >
...
</Create>

Expected to redirect to the absolute uri returned from the callback /resourceA/1/resourceB/2/resourceC/3

What happened instead:
instead I was redirected to /1/resourceB/2/resourceC/3 , according to the code of redirect function from ra-core

            } else if (typeof redirectTo === 'function') {
                const target: To = redirectTo(resource, id, data);
                const absoluteTarget =
                    typeof target === 'string'
                        ? `${basename}/${target}`
                        : {
                              pathname: `${basename}/${target.pathname}`,
                              ...target,
                          };
                navigate(absoluteTarget, {
                    state: { _scrollToTop: true, ...state },
                });
                return;

the result will be <basename>//resourceA/1/resourceB/2/resourceC/3 the double slash is causing the issue I belive, I would expect the check for leading slash before concatination

Environment

  • React-admin version: 5.4.3
  • Browser: Edge
@fzaninotto
Copy link
Member

I want to be sure about the problem you meet:

  1. the basename has a trailing slash
  2. the redirect target has a leading slash
  3. the resulting URI has a double slash

Is it the right description? If so, I don't see a bug. You should either remove the trailing slash from 1 or the leading slash from 2.

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

No branches or pull requests

2 participants