Search code examples
reactjsreact-nativehttp-redirectdeep-linkingfirebase-hosting

Using React and Google Hosting, how can I redirect all links that end with /posts/### where ### is any post id


I have a react site that is set up and being used to share deep links into my react native app. That is all working as expected however I'm trying to redirect people who do not have the app installed to the app store / play store.

The url I'm using for deep linking is the following:

https://example.com/posts/###

Is there a way to target all URLs that end with /posts/### and wildcard the id at the end?

Hosted on firebase, built with React.

Thanks!


Solution

  • Using React Router Redirect I was able to solve the issue!

    // example
    <Router>
      <Switch>
        <Redirect from="/posts/*" to="/getApp" />
        <Route exact path="/getApp" component={GetAppScreen} />
        <Route exact path="/contact" component={ContactScreen} />
         ...
      </Switch>
    </Router>