NextJsLinkAdapter
The link adapter for Next.js setups. It renders a plain anchor, not next/link, so a click loads a whole new page.
import { NextJsLinkAdapter } from '@salla.sa/twilight-theme-engine/nextjs';In plain words
With TwilightProvider's client={{ framework: 'nextjs' }}, the engine's Link renders through NextJsLinkAdapter. Today that is an ordinary <a href>: a click asks the browser for a new page, without Next.js's client-side navigation or prefetching.
Signature
const NextJsLinkAdapter: React.ForwardRefExoticComponent<
LinkProps & React.RefAttributes<HTMLAnchorElement>
>
// renders <a href={to ?? href ?? '/'}>; preload is ignoredExample
import { NextJsLinkAdapter } from '@salla.sa/twilight-theme-engine/nextjs';
// No locale is added for you: pass the full path.
export function LegalLinks({ locale }: { locale: string }) {
return (
<nav>
<NextJsLinkAdapter to={`/${locale}/privacy`}>Privacy</NextJsLinkAdapter>
<NextJsLinkAdapter to={`/${locale}/terms`}>Terms</NextJsLinkAdapter>
</nav>
);
}
How it behaves
The
hrefisto, elsehref, else/, exactly as given: no locale and no store segment are added.With
replace, a click is intercepted:history.replaceStatechanges the address and apopstateevent is dispatched, with no page load. Whatever listens topopstatemust render the new address.Under
client={{ framework: 'nextjs' }},TwilightProviderpairs it with anavigatethat assignswindow.location(a full page load) and applies no page class.
Gotchas
Do not use it in a TanStack theme. Its
hrefbypasses the router, so on localhost and the preview host it lacks the store segment the router adds, and every click reloads the whole page. UseLinkfrom@salla.sa/twilight-theme-engine/components/common.
Related
The anchor behind the engine's Link under TanStack Router: it adds the current language to internal paths and passes intent preloading on.
LinkAn anchor that moves between store pages without reloading, adding the language (and, on localhost or the preview host, the store) to the path.
LinkProviderTells the engine's Link which real anchor component to render; TwilightProvider supplies TanStack Router's, and tests can supply a plain one.
Source and docs
- Engine source:
packages/theme-engine/src/nextjs/link.tsx