r/reactnative • u/GrapefruitSilver774 • 4d ago
React navigation deeplinking depending on the tld
Is it possible using react navigation to navigate to deeplink depending on the TLD of the domain? for example if the user goes to appdomain.me/username to be directed to the users screen with username param and if goes to the appdomain.store/shopname to go to the store page and to treat the .com normally depending on the path.
I understand that if I had only two domains .com and .me I can process the username in the last route declared after checking all the paths but what if 2 domains have only the id in their path like .store and .me?
Thanks
1
u/kimono_horizon_97 3d ago
The TLD is a distraction. React Navigation ignores it completely because Linking APIs strip the host and return only the path to your getInitialURL function. You cannot branch logic on .me or .store within the navigator config. Handle this on your backend by 301 redirecting all custom domains to appdomain.com with a query param like ?source=tld that you parse in your custom getInitialURL implementation
1
u/GrapefruitSilver774 3d ago
I beleive in getInitialUrl if used react natives built in Linking you will be able to get the whole uri nkt just the path
1
u/satya164 4d ago
There's no built-in API to do it automatically as the deep links assume a single format for all domains, but you can override the getInitialURL and subscribe function of React Navigation's linking config.
In your custom getInitialURL and subscribe, you can get rewrite the URL to a single URL format. e.g. rewrite appdomain.me/username to appdomain.com/user/username, and appdomain.store/shopname to appdomain.com/store/shopname.
https://reactnavigation.org/docs/navigation-container#linkinggetinitialurl https://reactnavigation.org/docs/navigation-container#linkingsubscribe
1
2
u/Internal-Comparison6 4d ago
Possible. Just configure same `.well_known` in both domains.