简体   繁体   中英

how to create a button, pressable or a touchable opacity that redirects us to a website using react native

hey everyone I am newbie at react native and i want to know how to create a button, touchableopacity or a pressable that redirects us to a website using react native

Simply, there ir a module from React Native called Linking Doc where you can use the function openURL where the input argument is just your website link.

Full example:

import { Linking, Text, TouchableOpacity } from 'react-native'

 <TouchableOpacity style={{ width: 100, height: 60, backgroundColor: "red" }} onPress={() => Linking.openURL("https://stackoverflow.com")} > <Text> Go to my website </Text> </TouchableOpacity>

This function redirect to the default external browser of the device. If you want to use the native WebView check this library WebView (which few versions ago was included on react-native library)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM