@@ -4,6 +4,7 @@ import NextLink, { type LinkProps as NextLinkProps } from 'next/link';
44import React from 'react' ;
55
66import { tcls } from '@/lib/tailwind' ;
7+ import { checkIsAnchor , resolveAnchorURL } from '@/lib/urls' ;
78import { type TrackEventInput , useTrackEvent } from '../Insights' ;
89import { NavigationStatusContext } from '../hooks' ;
910import { isExternalLink , toNonEmbedLink } from '../utils/link' ;
@@ -88,12 +89,20 @@ export function Link(props: LinkProps) {
8889 const trackEvent = useTrackEvent ( ) ;
8990 const forwardedClassNames = useClassnames ( classNames || [ ] ) ;
9091 const isExternal = isExternalServer ( href ) ;
92+ const isAnchor = checkIsAnchor ( href ) ;
9193 const { target, rel } = getTargetProps ( props , { externalTarget, isExternal } ) ;
9294
9395 const onClick = ( event : React . MouseEvent < HTMLAnchorElement > ) => {
9496 // Only trigger navigation context for internal links in the same window without modifier keys (i.e. open in new tab).
9597 if ( ! isExternal && target !== '_blank' && ! event . ctrlKey && ! event . metaKey ) {
96- onNavigationClick ( href ) ;
98+ if ( isAnchor ) {
99+ event . preventDefault ( ) ;
100+ const resolvedHref = resolveAnchorURL ( href , window . location ) ;
101+ window . history . pushState ( null , '' , resolvedHref ) ;
102+ onNavigationClick ( resolvedHref ) ;
103+ } else {
104+ onNavigationClick ( href ) ;
105+ }
97106 }
98107
99108 const isExternalOnClient = isExternalClient ( href ) ;
0 commit comments