[change] Linking API

Linking updates the application document's URL rather than opening a new
window. This change also makes deep-linking work.
This commit is contained in:
Nicolas Gallagher
2018-05-08 13:59:29 -07:00
parent 19b356aaea
commit 0ee3310290
+7 -9
View File
@@ -9,6 +9,7 @@
*/ */
import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment'; import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment';
import invariant from 'fbjs/lib/invariant';
const initialURL = canUseDOM ? window.location.href : ''; const initialURL = canUseDOM ? window.location.href : '';
@@ -28,19 +29,16 @@ const Linking = {
} catch (e) { } catch (e) {
return Promise.reject(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 open = url => {
const anchor = document.createElement('a'); if (canUseDOM) {
anchor.target = '_blank'; // :( window.location = new URL(url, window.location).toString();
anchor.rel = 'noopener';
anchor.href = url;
const body = document.body;
if (body) {
body.appendChild(anchor);
anchor.click();
body.removeChild(anchor);
} }
}; };