redirect
本页内容

redirect

摘要

参考文档 ↗

一个重定向 Response。设置状态码和 Location 标头。默认为 302 Found

import { redirect } from "react-router";

export async function loader({ request }: Route.LoaderArgs) {
  if (!isLoggedIn(request))
    throw redirect("/login");
  }

  // ...
}

参数

url

要重定向到的 URL。

init

要包含在响应中的状态码或 ResponseInit 对象。

返回

一个包含重定向状态和 Location 标头的 Response 对象。

文档和示例 CC 4.0
编辑