React Native - 解析 URL 以获取查询变量 [英] React Native - Parse URL to get Query Variable

查看:66
本文介绍了React Native - 解析 URL 以获取查询变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在寻找一种解析 URL 的方法,以获取从 Linking 接收到的 React Native 中的查询变量.

Looking for a way to parse a URL to get a query variable in React Native received from Linking.

我收到的 URL 类似于:

I'm receiving the URL as something like:

url-app-scheme://somePage?someVar=someVal

url-app-scheme://somePage?someVar=someVal

我想从 URL 中获取 someVar 值.

I'd like to get the someVar value from the URL.

有什么想法吗?

推荐答案

这应该可以解决问题

var url = "http://example.com?myVar=test&otherVariable=someData&number=123"

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

这篇关于React Native - 解析 URL 以获取查询变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆