Skip to content

[Bug]: absolute redirect fails while using base url #10052

@amsal

Description

@amsal

What version of React Router are you using?

6.8.0

Steps to Reproduce

  • Have a react router application hosted in a sub directory e.g. https://example.com/app1
  • https://example.com and https://example.com/app1 are two independent applications. Served using a reverse proxy

app1 is the base path and it is set using basename

const router = createBrowserRouter(
  [
    {
      id: "root",
      path: "/",
      element: (
        <>
          <div>Root</div>
          <Link to="/logout">Logout</Link>
        </>
      ),
    },
    {
      path: "/logout",
      loader: LogoutLoader,
    },
  ],
  {
    basename: "app1",
  }
);
export const LogoutLoader = async () => {
  return redirect("https://example.com");
};
  • Go to logout url https://example.com/app1/logout

Expected Behavior

LogoutLoader should redirect user to https://example.com as if it was an external redirect to somewhere like https://google.com. It should be a redirect via browser instead of react-router.

Actual Behavior

React router changes the browser URL but the content of the site is still from https://example.com/app1 instead of https://example.com. In the browser dev tools, no request is made to redirect URL.

Possible bug might be here

if (url.origin === currentUrl.origin) {

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