diff --git a/packages/remix-react/components.tsx b/packages/remix-react/components.tsx index a50e98dc9d7..9cb83a4fe17 100644 --- a/packages/remix-react/components.tsx +++ b/packages/remix-react/components.tsx @@ -296,6 +296,11 @@ function usePrefetchBehavior( */ let NavLink = React.forwardRef( ({ to, prefetch = "none", ...props }, forwardedRef) => { + // `location` is the unaltered href we will render in the tag for absolute URLs + let location = typeof to === "string" ? to : createPath(to); + let isAbsolute = + /^[a-z+]+:\/\//i.test(location) || location.startsWith("//"); + let href = useHref(to); let [shouldPrefetch, prefetchHandlers] = usePrefetchBehavior( prefetch, @@ -305,11 +310,13 @@ let NavLink = React.forwardRef( <> - {shouldPrefetch ? : null} + {shouldPrefetch && !isAbsolute ? ( + + ) : null} ); } @@ -325,8 +332,8 @@ export { NavLink }; */ let Link = React.forwardRef( ({ to, prefetch = "none", children, ...props }, forwardedRef) => { + // `location` is the unaltered href we will render in the tag for absolute URLs let location = typeof to === "string" ? to : createPath(to); - let isAbsolute = /^[a-z+]+:\/\//i.test(location) || location.startsWith("//");