Skip to content

Commit

Permalink
chore: add external support to NavLink
Browse files Browse the repository at this point in the history
Signed-off-by: Logan McAnsh <[email protected]>
  • Loading branch information
mcansh committed Jan 25, 2023
1 parent 82fcda7 commit 81a92dc
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/remix-react/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ function usePrefetchBehavior(
*/
let NavLink = React.forwardRef<HTMLAnchorElement, RemixNavLinkProps>(
({ to, prefetch = "none", ...props }, forwardedRef) => {
// `location` is the unaltered href we will render in the <a> 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,
Expand All @@ -305,11 +310,13 @@ let NavLink = React.forwardRef<HTMLAnchorElement, RemixNavLinkProps>(
<>
<RouterNavLink
ref={forwardedRef}
to={to}
to={location}
{...props}
{...prefetchHandlers}
/>
{shouldPrefetch ? <PrefetchPageLinks page={href} /> : null}
{shouldPrefetch && !isAbsolute ? (
<PrefetchPageLinks page={href} />
) : null}
</>
);
}
Expand All @@ -325,8 +332,8 @@ export { NavLink };
*/
let Link = React.forwardRef<HTMLAnchorElement, RemixLinkProps>(
({ to, prefetch = "none", children, ...props }, forwardedRef) => {
// `location` is the unaltered href we will render in the <a> tag for absolute URLs
let location = typeof to === "string" ? to : createPath(to);

let isAbsolute =
/^[a-z+]+:\/\//i.test(location) || location.startsWith("//");

Expand Down

0 comments on commit 81a92dc

Please sign in to comment.