3

I have a mobile app with Expo.

To move from one screen to the other, I use react-navigation's navigation.navigate(SCREEN_NAME)

I am building the web version of this app and would like my buttons to be links, instead of using navigate. This way, users will be able to open links in another tab.

I found out about useLinkProps, which works great but doesn't work with screen names. I do not want to hardcode the urls in my code and would like to somehow compute them from the screen names.

For example, navigate("AddMessageScreen") might open the url /message/add or /profile/598/message/add based on your current route. I want to keep this automatic selection of the proper URL with useLinkProps.

Any idea how to achieve that?

Ryan Pergent
  • 4,432
  • 3
  • 36
  • 78

1 Answers1

0

To achieve this your will have first to configure links in react-navigation.

Not a trivial thing but it's well documented: configuring-links

Then you will have a url-like structure for all your routes that suites well for browser integration.

ElForastero
  • 26
  • 1
  • 2
  • 1
    I already have an extensive config for my website so I know what URLs to use with `useLinkProps`. The problem is that I currently have to hardcode the "to" parameter of `useLinkProps`. Instead, I would like the "to" URL to be dynamic and calculated from the name of the Screen the button should lead to. – Ryan Pergent Feb 05 '21 at 13:07