首页 > 解决方案 > url.pathname 或 url.searchParams 不是 android react native 中的函数

问题描述

我正在研究 android react native 项目,我得到了深度链接的 URL。我正在尝试从以下 url 中查找路径名和搜索参数:https ://test.xxx.com/test/test?test=moduleName 。

var url = URL(" https://test.xxx.com/test/test?test=moduleName "); 控制台.log(url.pathName);

该代码给出了以下异常“错误:未实现”。我还从 node 安装了 URL 包。我错过了什么?

标签: androidreact-nativeurl

解决方案


看看这个用于 React Native 的 URL polyfill

import { URL, URLSearchParams } from 'react-native-url-polyfill';

const url = new URL("https://test.xxx.com/test/test?test=moduleName");
const searchParams = new URLSearchParams('q=GitHub');

另请注意 - React Native 在 JavascriptCore 引擎中运行,而 Node.js/Web 在 v8 Javascript 引擎中运行。

Node.js 提供了自己的专有功能 - 流、加密、http 等。此功能在 React Native 中不可用,在第三方包(如node-libs-react-native)之外


推荐阅读