You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ExternalLink.tsx 700B

123456789101112131415161718192021222324
  1. import { Link } from 'expo-router';
  2. import { openBrowserAsync } from 'expo-web-browser';
  3. import { type ComponentProps } from 'react';
  4. import { Platform } from 'react-native';
  5. type Props = Omit<ComponentProps<typeof Link>, 'href'> & { href: string };
  6. export function ExternalLink({ href, ...rest }: Props) {
  7. return (
  8. <Link
  9. target="_blank"
  10. {...rest}
  11. href={href}
  12. onPress={async (event) => {
  13. if (Platform.OS !== 'web') {
  14. // Prevent the default behavior of linking to the default browser on native.
  15. event.preventDefault();
  16. // Open the link in an in-app browser.
  17. await openBrowserAsync(href);
  18. }
  19. }}
  20. />
  21. );
  22. }