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

Redirect with query search fails in react-router #227

Open
spaenleh opened this issue Oct 10, 2023 · 0 comments
Open

Redirect with query search fails in react-router #227

spaenleh opened this issue Oct 10, 2023 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@spaenleh
Copy link
Member

spaenleh commented Oct 10, 2023

Sentry ref
Error Message:

Cannot include a '?' character in a manually specified `to.pathname` field [{"pathname":"https://builder.graasp.org/items/582959ac-ebf1-44b4-9fed-136fd0ae51a1?_gl=1*1jq6eg*_ga*MTUyMTM3ODk2OS4xNjk0NzA5OTQ1*_ga_KQVPBFX8MF*MTY5NjUxMjI4Mi40LjEuMTY5NjUxMz...

We use the react-router navigate function to redirect the user where they were before requesting to signin/up. But this url might contain a query search with additional parameters. In this case the ?_gl= is a Google Analytics cross site tracking parameter. This fails because react-router can't match a pathname with a search query.

Solution: Provide the navigate function the pathname and search separately like so (take from reference below):

const returnToUrl = new URL(returnTo, window.location.origin);
navigate({
     pathname: returnToUrl.pathname,
     search: returnToUrl.searchParams.toString()
});

Reference: remix-run/react-router#9613 (comment)

@spaenleh spaenleh added the bug Something isn't working label Oct 10, 2023
@spaenleh spaenleh self-assigned this Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant