mirror of
https://github.com/zhigang1992/react-native-web.git
synced 2026-03-26 09:14:15 +08: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:
@@ -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();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user