dev
redirectDocument

redirectDocument

This is a small wrapper around redirect that will trigger a document-level redirect to the new location instead of a client-side navigation.

This is most useful when you have a React Router app living next to a separate app on the same domain and need to redirect from the React Router app to the other app via window.location instead of a React Router navigation:

import { redirectDocument } from "react-router-dom";

const loader = async () => {
  const user = await getUser();
  if (!user) {
    return redirectDocument("/otherapp/login");
  }
  return null;
};

Type Declaration

type RedirectFunction = (
  url: string,
  init?: number | ResponseInit
) => Response;

url

The URL to redirect to.

redirectDocument("/otherapp/login");

init

The Response options to be used in the response.

Docs and examples CC 4.0
Edit