如何从 URL GET 参数中获取 react native webview 中的值?

How to get the value from the URL GET parameters in react native webview?

我有这个回复

webViewState Object {
  "canGoBack": true,
  "canGoForward": false,
  "loading": false,
  "navigationType": "other",
  "target": 65507,
  "title": "السداد بواسطة PayPal - راجع مدفوعاتك",
  "url": "https://example.com/?paymentId=PAYID-L2ILTHQ83R55588UV606981X&token=EC-5EB6693455269621L&PayerID=BLG98CXTZAX8S",
}

如何从 URL 访问 paymentId 和 PayerID 参数??

我试过这一行,但是 returns 两者都未定义 const { PayerID, paymentId } = webViewState.url;

有什么帮助吗?

获取数据后,您可以执行以下操作:

var regexp = /[?&]([^=#]+)=([^&#]*)/g,params = {},check;
while (check = regexp.exec(webViewState.url)) {
  params[check[1]] = check[2];
}
console.log("params",params)

params 会给你一个这样的对象

Object {
  "PayerID": "BLG98CXTZAX8S",
  "paymentId": "PAYID-L2ILTHQ83R55588UV606981X",
  "token": "EC-5EB6693455269621L",
}

希望对您有所帮助!