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(); } };