diff --git a/apps/blog/src/components/utm-persistence.tsx b/apps/blog/src/components/utm-persistence.tsx index 2ba8c3b377..d9c041b659 100644 --- a/apps/blog/src/components/utm-persistence.tsx +++ b/apps/blog/src/components/utm-persistence.tsx @@ -76,18 +76,29 @@ export function UtmPersistence() { } const nextHref = `${targetUrl.pathname}${targetUrl.search}${targetUrl.hash}`; - const internalPathname = - targetUrl.pathname === BLOG_PREFIX - ? "/" - : targetUrl.pathname.replace(new RegExp(`^${BLOG_PREFIX}(?:/|$)`), "/"); - const nextInternalHref = - `${internalPathname}${targetUrl.search}${targetUrl.hash}`; + const isBlogPath = + targetUrl.pathname === BLOG_PREFIX || + targetUrl.pathname.startsWith(`${BLOG_PREFIX}/`); const isModifiedClick = event.metaKey || event.ctrlKey || event.shiftKey || event.altKey; - if (isInternalLink && anchor.target !== "_blank" && !isModifiedClick) { + if ( + isInternalLink && + isBlogPath && + anchor.target !== "_blank" && + !isModifiedClick + ) { + const internalPathname = + targetUrl.pathname === BLOG_PREFIX + ? "/" + : targetUrl.pathname.replace( + new RegExp(`^${BLOG_PREFIX}(?:/|$)`), + "/", + ); event.preventDefault(); - router.push(nextInternalHref); + router.push( + `${internalPathname}${targetUrl.search}${targetUrl.hash}`, + ); return; } diff --git a/apps/site/src/components/utm-persistence.tsx b/apps/site/src/components/utm-persistence.tsx index d0c1c90c76..31c204b494 100644 --- a/apps/site/src/components/utm-persistence.tsx +++ b/apps/site/src/components/utm-persistence.tsx @@ -80,7 +80,20 @@ export function UtmPersistence() { const isModifiedClick = event.metaKey || event.ctrlKey || event.shiftKey || event.altKey; - if (isInternalLink && anchor.target !== "_blank" && !isModifiedClick) { + // Paths proxied to other apps via rewrites — must use full navigation + // so the server-side rewrite kicks in instead of client-side routing. + const isProxiedPath = + targetUrl.pathname === "/docs" || + targetUrl.pathname.startsWith("/docs/") || + targetUrl.pathname === "/blog" || + targetUrl.pathname.startsWith("/blog/"); + + if ( + isInternalLink && + !isProxiedPath && + anchor.target !== "_blank" && + !isModifiedClick + ) { event.preventDefault(); router.push(nextHref); return;