Get path to Screen from its name, to use with useLinkProps

540 views Asked by At

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?

1

There are 1 answers

1
ElForastero On

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.