25 lines
746 B
TypeScript
Raw Permalink Normal View History

import { Link, RelativePathString } from 'expo-router';
2025-01-28 08:19:46 -06:00
import { openBrowserAsync } from 'expo-web-browser';
import { type ComponentProps } from 'react';
import { Platform } from 'react-native';
type Props = Omit<ComponentProps<typeof Link>, 'href'> & { href: string };
export const ExternalLink = ({ href, ...rest }: Props) => {
2025-01-28 08:19:46 -06:00
return (
<Link
2025-01-28 08:45:02 -06:00
target='_blank'
2025-01-28 08:19:46 -06:00
{...rest}
href={href as RelativePathString}
2025-01-28 08:19:46 -06:00
onPress={async (event) => {
if (Platform.OS !== 'web') {
// Prevent the default behavior of linking to the default browser on native.
event.preventDefault();
// Open the link in an in-app browser.
await openBrowserAsync(href);
}
}}
/>
);
};