redirectDocument
這是包覆在 redirect
的一個小型包裝,它將觸發文件層級重定向到新位置,而不是用戶端導覽。
當您有一個 React 路由器應用程式在同一個網域中與另一個獨立的應用程式並存時,最常應用此方式,並需要透過 window.location
而不是 React 路由導覽,從 React 路由器應用程式重新導向到另一應用程式中
import { redirectDocument } from "react-router-dom";
const loader = async () => {
const user = await getUser();
if (!user) {
return redirectDocument("/otherapp/login");
}
return null;
};
type RedirectFunction = (
url: string,
init?: number | ResponseInit
) => Response;
url
要重新導向的 URL。
redirectDocument("/otherapp/login");
init
Response 選項用於回傳中。