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

[Bug]: "Failed to construct 'URL': Invalid URL" error when using lazy loading and double slash in URL #11188

Open
mskrzypek opened this issue Jan 12, 2024 · 2 comments
Labels

Comments

@mskrzypek
Copy link

mskrzypek commented Jan 12, 2024

What version of React Router are you using?

6.21.2

Steps to Reproduce

  1. Prepare routing with lazy loaded component at root path:

    createBrowserRouter([
       {
         path: "/",
         lazy: async () => {
           const { Slash } = await import("./components");
           return {
             Component: () => <Slash />,
           };
         },
       },
    ]);
  2. Open app in browser with additional slash at the end of the URL, ie. http://localhost:3000//

Expected Behavior

Lazy loaded component is rendered at root URL, even though there are two slashes in the URL.

Actual Behavior

Lazy loaded component is not loading, there is Failed to construct 'URL': Invalid URL error. When component is rendered with element, it is being rendered correctly.

I prepared a reproduction example: https://codesandbox.io/p/sandbox/blissful-ritchie-9szrnk

@mskrzypek mskrzypek added the bug label Jan 12, 2024
@fillinmar
Copy link

unfortunately, i have the same problem, is there any solution?

@hjonasson
Copy link

Looks like a duplicate of #11429

@mskrzypek if it helps I investigated that one slightly. It looks like official URL spec that <host>// should not be a valid URL. You wrote in Expected behavior that the Slash component should get rendered at the root. Why do you expect that in the // route? I am asking as it looks like a nested route to me if anything.

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

No branches or pull requests

3 participants