import {useContext} from 'react'; import {AppProxyProviderContext} from '../AppProxyProvider'; export interface AppProxyLinkProps extends React.DetailedHTMLProps< React.AnchorHTMLAttributes, HTMLAnchorElement > { href: string; } /** * Sets up an `` HTML element that works when rendered behind an app proxy. * * Supports any properties accepted by the `` HTML element. * * @example * Link to a different route. * Use an `AppProxyLink` within an `AppProxyProvider` to link to a different proxied route. * ```ts * // /app/routes/**\/*.ts * import {authenticate} from '~/shopify.server'; * import {AppProxyProvider, AppProxyLink} from '@shopify/shopify-app-react-router/react'; * * export async function loader({ request }) { * await authenticate.public.appProxy(request); * * return json({ appUrl: process.env.SHOPIFY_APP_URL }); * } * * export default function App() { * const { appUrl } = useLoaderData(); * * return ( * * Link to another route * * ); * } * ``` */ export function AppProxyLink(props: AppProxyLinkProps) { const context = useContext(AppProxyProviderContext); if (!context) { throw new Error( 'AppProxyLink must be used within an AppProxyProvider component', ); } const {children, href, ...otherProps} = props; return ( {children} ); }