main
Branches
main (2.16.8)dev
Versions
2.16.81.19.3v0.21.0
React Router v7 has been released. View the docs
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 Remix app living next to a non-Remix app on the same domain and need to redirect from the Remix app to the non-Remix app:

import { redirectDocument } from "@remix-run/node"; // or cloudflare/deno  export const action = async () => {  const userSession = await getUserSessionOrWhatever();   if (!userSession) {  // Assuming `/login` is a separate non-Remix app  return redirectDocument("/login");  }   return json({ ok: true }); }; 

Just like redirect, it accepts a status code or a ResponseInit as the second parameter:

redirectDocument(path, 301); redirectDocument(path, 303); 
redirectDocument(path, {  headers: {  "Set-Cookie": await commitSession(session),  }, }); 
Docs and examples licensed under MIT