URL
标准 URL API 在所有 Expo 支持的平台上可用。
标准 URL API 在所有 Expo 支持的平台上均可用。
¥The standard URL API is available on all Expo-supported platforms.
安装
¥Installation
此 API 是 expo
软件包的一部分。在原生平台上,内置 URL
和 URLSearchParams
实现取代了 react-native
中的垫片。请参阅 Web 和 Node.js 的 浏览器和服务器运行时支持。
¥This API is part of the expo
package. On native platforms, built-in URL
and URLSearchParams
implementations replace the shims in react-native
. Refer to the browser and server runtime support for web and Node.js.
用法
¥Usage
const url = new URL('https://expo.dev');
const params = new URLSearchParams();
一致性
¥Conformance
Expo 的内置 URL 支持已尝试完全符合 符合规范 标准。
¥Expo's built-in URL support attempts to be fully spec compliant.
唯一缺少的例外是原生平台当前不支持主机名中的 非 ASCII 字符。
¥The only missing exception is that native platforms do not currently support non-ASCII characters in the hostname.
请考虑以下示例:
¥Consider the following example:
console.log(new URL('http://🥓').toString());
输出如下:
¥This outputs the following:
-
Web,Node.js:
http://xn--pr9h/
-
Android、iOS:
http://🥓/