Response: redirect() 静的メソッド

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2017.

redirect()Response インターフェイスのメソッドで、指定された URL へのリダイレクトをもたらす Response を返します。

メモ: これは主にサービスワーカー API に関連しています。 制御するサービスワーカーは、ページのリクエストに介入し、希望通りにリダイレクトすることができます。 もしサービスワーカーが上流に送信を行うと、実際に本当のリダイレクトが発生します。

構文

js
Response.redirect(url)
Response.redirect(url, status)

引数

url

新しいレスポンスの発信元 URL。

status 省略可

レスポンスのステータスコードを示すオプションの番号で、301302303307308 のいずれかです。省略されたときは、既定で 302 Found が使われます。

返値

Response オブジェクト。

例外

RangeError

指定されたステータスがリダイレクトステータスではない場合。

TypeError

指定された URL が不正な場合。

js
Response.redirect("https://www.example.com", 302);

仕様書

Specification
Fetch
# ref-for-dom-response-redirect①

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
redirect() static method

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報