Skip to content

[Bug]: "TypeError: URL constructor: // is not a valid URL" while using data router #11911

@Blargel

Description

@Blargel

EDIT: The report below is incorrect, please see this comment for the real issue.


What version of React Router are you using?

6.26.0

Steps to Reproduce

Luckily, this can be reproduced in the data router StackBlitz example.
https://stackblitz.com/github/remix-run/react-router/tree/main/examples/data-router

If you edit url in the preview pane to add double slash ("//") at the end, you will get an invalid URL error and no route will render, not even the default 404 page.

Expected Behavior

I expect that the application would render the 404 page. Alternatively, it would also be okay if react router removed extra trailing slashes automatically.

Actual Behavior

An error is being thrown. In the case of the StackBlitz, a developer error page comes up, and when dismissed, the application does is not render anything, not even the root route's Layout component. In the case of my own applications, one of them has the same behavior, and another somehow manages to render the root layout, but none of the links work. Both applications will display the same error in the console, if it's open.

I recognize that a double slash is indeed an invalid url. However, this is a potential thing that an end user can do, and that I as a developer cannot seem to handle on my own since the error is coming from react router's internals.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions