redirectDocument
これは、クライアントサイドのナビゲーションではなく、新しいロケーションへのドキュメントレベルのリダイレクトをトリガーするredirectの小さなラッパーです。
これは、同じドメイン上にRemixアプリと非Remixアプリが共存しており、Remixアプリから非Remixアプリにリダイレクトする必要がある場合に最も役立ちます。
import { redirectDocument } from "@remix-run/node"; // または cloudflare/deno
export const action = async () => {
const userSession = await getUserSessionOrWhatever();
if (!userSession) {
// `/login` が別の非Remixアプリであると仮定
return redirectDocument("/login");
}
return json({ ok: true });
};redirectと同様に、ステータスコードまたは ResponseInit を2番目のパラメータとして受け入れます。
redirectDocument(path, 301);
redirectDocument(path, 303);redirectDocument(path, {
headers: {
"Set-Cookie": await commitSession(session),
},
});