mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-06-03 10:46:19 +00:00
[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:
+7
-9
@@ -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);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user