Skip to content

Removing basename results in empty location.pathname #483

@catamphetamine

Description

@catamphetamine

location.pathname is supposed to always be non-empty.

If basename is set to /basename and the user navigates to /basename URL, createBasenameMiddleware() simply strips the whole string from the URL and the result is incorrect: pathname: "".

The fix would be adding || '/' after location.pathname.slice(pathnamePrefix.length):

    makeLocation: (location) => ({
      ...location,
      pathname:
        location.pathname.indexOf(pathnamePrefix) === 0
          ? location.pathname.slice(pathnamePrefix.length)
          : null,
    }),

If anyone's interested, I published this workaround as part of navigation-stack package:
https://www.npmjs.com/package/navigation-stack

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