首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >react本机Linking.getInitialURL不返回查询参数

react本机Linking.getInitialURL不返回查询参数
EN

Stack Overflow用户
提问于 2020-01-07 00:34:22
回答 2查看 2.7K关注 0票数 0

文档之后,您可以使用Linking.getInitialURL方法获取应用程序是用哪个URL打开的(例如,如果从web浏览器打开),如下所示:

代码语言:javascript
复制
// called from exp://expo.io/@solbiatialessandro/GettingIntoYc
export default function App(props) {
  Linking.getInitialURL().then((url) => {
    if (url) {
      console.log('Initial url is: ' + url);
      // 'Initial url is exp://expo.io/@solbiatialessandro/GettingIntoYc'
    }
  }).catch(err => console.error('An error occurred', err));
  return (<AppNavigator />);
}

上面的操作是正确的,但是我无法使用下面的代码片段检索添加到url中的查询参数

代码语言:javascript
复制
// called with exp://expo.io/@solbiatialessandro/GettingIntoYc?test=1234
export default function App(props) {
  Linking.getInitialURL().then((url) => {
    if (url) {
      let { path, queryParams } = Linking.parse(url);
      // path: exp://expo.io/@solbiatialessandro/GettingIntoYc
      // queryParams: null
    }
  }).catch(err => console.error('An error occurred', err));
  return (<AppNavigator />);
}

而且,如果我尝试console.log(url),我会得到没有?test=1234的输入url,所以它看起来被链接模块丢弃了。

EN

回答 2

Stack Overflow用户

发布于 2020-06-16 16:57:22

我有一个对我有用的解决方案:

也许您可以尝试使用'exp://expo.io/@solbiatialessandro/GettingIntoYc?test=1234',调用它,而不是用"exp://expo.io/@solbiatialessandro/GettingIntoYc/index.exp?test=1234“调用它。

注意:我尝试过的链接将我重定向到一个已发布(未构建)的世博会应用程序(SDK37.0.0)。另外,仅仅使用'exp://expo.io/@solbiatialessandro/GettingIntoYc?test=1234‘可以在IOS设备上进行测试,但是它不能在安卓设备上工作。

希望这能帮上忙!

票数 2
EN

Stack Overflow用户

发布于 2020-04-26 13:29:40

很奇怪,但这对我来说很管用

代码语言:javascript
复制
let newURL = Linking.parse(url);
console.log(newURL.queryParams);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59620714

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档