Automatically redirect from react js page to mobile app

Viewed 526

In my mobile app, I can share a link: http://www.myapp.com/share/{id} If another user receive the link and he has the app installed and he clicks on the link, I want that his app will automatically open. Otherwise, If he hasn't the app, he can browse my web page http://www.myapp.com/share/{id}

I created a react js page for the url above, and if I click on the button or in the hyperlink, my app will open correctly. I tried a window.location to my mobile app, but it doesn't work. So, I was thinking to simulate a click on one of these objects, hiding their visibility to the user, so the user will be automatically redirected to the mobile app.

But I'm open to any kind of solution.

    export default class Share extends Component {

       componentDidMount() {

          setTimeout(() => {
            window.location='myapp://redirect/acceptShare/12345'; //doesn't work
          }, 500);
      }

      render() {
        return (
            <div>
                <button
                type="button" id="but" name="nbut"
                onClick={(e): void => {
                  e.preventDefault();
                  window.location.href='myapp://redirect/acceptShare/12345'; 
//the click works
                  }}> Click here</button>

                <a name='nhid2' id='hid2' href='myapp://redirect/acceptShare/12345' >click2</a> 
//the click works
            </div>
          )
      }
    }
0 Answers
Related