我正在进行:
import React from 'react';
import PropTypes from 'prop-types';
import { TouchableOpacity, Linking } from 'react-native';
/**
* Used to create external link to other websites
*/
class ExternalLink extends React.Component {
_openLink = async () => {
const { href } = this.props;
if (await Linking.canOpenURL(href)) {
await Linking.openURL(href);
}
};
render() {
const { href, children, ...rest } = this.props;
return (
<TouchableOpacity
accessibilityRole="link"
onPress={this._openLink} // eslint-disable-line no-underscore-dangle
href={href}
{...rest}
>
{children}
</TouchableOpacity>
);
}
}
ExternalLink.propTypes = {
/** External URL */
href: PropTypes.string.isRequired,
/** Any node */
children: PropTypes.node.isRequired,
};
export default ExternalLink;
然而,当前在当前标签页打开,有没有一种方法可以在新标签页中打开URL?