首页 > 解决方案 > 如何使用导航请求模式?

问题描述

据说这种请求模式是一种特殊模式。它是如此特别,以至于我找不到使用它的示例,并且下面的代码在控制台中引发了错误。

fetch("http://ytrezq.sdfeu.org/flashredirect/?https://github.com/git-receive-pack", {mode:"navigate"})
  .then(function(response) {console.log(response);});;

标签: javascriptfetch-api

解决方案


While the mode option takes a value that is from the Request.mode interface, not all of the possible Request.mode values are allowed for fetch.

From MDN:

navigate — A mode for supporting navigation. The navigate value is intended to be used only by HTML navigation. A navigate request is created only while navigating between documents.

So to use it, click a regular link in an HTML document or assign a new URL to the location global. The browser will set the mode to navigate under the hood.


推荐阅读