From 0ee3310290f7df59ed6e4910e4af1412fc17afe1 Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Tue, 8 May 2018 13:59:29 -0700 Subject: [PATCH] [change] Linking API Linking updates the application document's URL rather than opening a new window. This change also makes deep-linking work. --- .../src/exports/Linking/index.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/react-native-web/src/exports/Linking/index.js b/packages/react-native-web/src/exports/Linking/index.js index 9fb5e03d..bdfe1c46 100644 --- a/packages/react-native-web/src/exports/Linking/index.js +++ b/packages/react-native-web/src/exports/Linking/index.js @@ -9,6 +9,7 @@ */ import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment'; +import invariant from 'fbjs/lib/invariant'; const initialURL = canUseDOM ? window.location.href : ''; @@ -28,19 +29,16 @@ const Linking = { } catch (e) { return Promise.reject(e); } + }, + _validateURL(url: string) { + invariant(typeof url === 'string', 'Invalid URL: should be a string. Was: ' + url); + invariant(url, 'Invalid URL: cannot be empty'); } }; const open = url => { - const anchor = document.createElement('a'); - anchor.target = '_blank'; // :( - anchor.rel = 'noopener'; - anchor.href = url; - const body = document.body; - if (body) { - body.appendChild(anchor); - anchor.click(); - body.removeChild(anchor); + if (canUseDOM) { + window.location = new URL(url, window.location).toString(); } };