From 40606c7cbc46ebbc8d06166c24f0d4896b252ede Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Billioud?= Date: Fri, 18 Sep 2020 22:09:22 +0200 Subject: [PATCH] Provide better API for opening in new tab Opening link in a new tab is something quite common on web nowadays. This use case should be handled by react-native-web. Currently, the only solution is [described here](https://github.com/necolas/react-native-web/issues/162). And we can all agree I think that this is not what we could think as a satisfying solution. Here is my proposal. It should be transparent for native and provide the ability for web. --- packages/react-native-web/src/exports/Linking/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/react-native-web/src/exports/Linking/index.js b/packages/react-native-web/src/exports/Linking/index.js index c846e2d203..0774919e9d 100644 --- a/packages/react-native-web/src/exports/Linking/index.js +++ b/packages/react-native-web/src/exports/Linking/index.js @@ -22,9 +22,9 @@ const Linking = { getInitialURL(): Promise { return Promise.resolve(initialURL); }, - openURL(url: string): Promise { + openURL(url: string, target?: '_blank'): Promise { try { - open(url); + open(url, target); return Promise.resolve(); } catch (e) { return Promise.reject(e); @@ -36,9 +36,9 @@ const Linking = { } }; -const open = url => { +const open = (url: string, target?: '_blank') => { if (canUseDOM) { - window.location = new URL(url, window.location).toString(); + window.open(url, target).focus(); } };