首页 > 解决方案 > 反应:a.href 在我的 index.jsx 文件中不起作用

问题描述

我有一个处理 deepLink 的 index.jsx 文件。我的目标是当我在这个重定向页面上时,检测是否安装了应用程序。如果已安装,则打开应用程序,如果没有转到 PlayStore。

目前,当我在这个页面上时,它只是坐在上面什么都不做。a.click() 函数由于某种原因无法正常工作,并且不知道为什么。

const Redirect = () => {
  const os = getOs();

  const redirectToApp = () => {
    if (os === 'android') {
      const a = document.createElement('a');
      a.href = 'Intent://open/#Intent;scheme=lxxxxx;package=com.txxxxx.lxxxxx;end';
      a.click();
    }
  };

  window.onload = redirectToApp();

  return (
    <Wrapper>
      <RedirectPanel p={8}>
        <Flex alignItems="center" flexDirection="column">
          <H3 mb={2} textAlign="center">
            Redirecting to MobileApp
          </H3>
          <RedirectImg />
          <Text fontSize="18px" textAlign="center">
            Please wait a few moments
          </Text>
        </Flex>
      </RedirectPanel>
    </Wrapper>
  );
};

在我的 android 设备上,我打开了一个 js 编译器并运行以下代码:

const a = document.createElement('a');
          a.href = 'Intent://open/#Intent;scheme=lxxxxx;package=com.txxxxx.lxxxxx;end';
          a.click();

很好用。如果已安装,则打开,否则将转到 PlayStore。但在我的 index.jsx 中它不起作用。请寻求帮助!!!

标签: androidreactjsdeep-linkingandroid-deep-link

解决方案


推荐阅读