Skip to content

TypeError on URLs with empty path segments #84

@s177312

Description

@s177312

Version
2.9.1

Describe the bug
The TypeError is thrown when the current URL only has empty path segments and atleast 2 empty path segments.

Example 1:
Image

Image

Example 2:
Image

Image

Code:
Image

To Reproduce

  1. Use the LocationProvider component.
  2. Navigate to an URL with only empty path segments and more than one empty path segments.

Expected behavior
Should navigate to either the default route or a "/" route.

Fix
The error is thrown by the LocationProvider component inside the first useMemo call.
When the new URL(url, base) is called with a relative URL '//'(or more empty slashes), then it seems it is treated as a protocol-relative URL(https://en.wikipedia.org/wiki/URL#Protocol-relative_URLs).

Example1:
Image

Image

Created here:

Image

So these URL objects don't match the actual URL anymore.

An idea to fix is to pass the full URL to the URL constructor as a single argument.
That seems to work fine.

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions