File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { Counter } from "@/components/Counter" ;
22import { LocaleSwitcher } from "@lingo.dev/compiler/react" ;
3- import Link from "next/link " ;
3+ import { Link } from "@/components/LocaleLink " ;
44import { ServerChild } from "@/components/ServerChild" ;
55import { ClientChildWrapper } from "@/components/ClientChildWrapper" ;
66
@@ -22,7 +22,7 @@ export default function Home() {
2222 < header className = "flex justify-between p-10 w-full" >
2323 < span > Lingo.dev compiler Next demo</ span >
2424 < nav >
25- < Link href = "/ test" > Test</ Link > 1
25+ < Link href = "test" > Test</ Link > 1
2626 </ nav >
2727 < LocaleSwitcher
2828 locales = { [
Original file line number Diff line number Diff line change 1+ "use client" ;
2+
3+ import NextLink from "next/link" ;
4+ import { useLingoContext } from "@lingo.dev/compiler/react" ;
5+ import type { ComponentProps } from "react" ;
6+
7+ /**
8+ * Link component that automatically prefixes hrefs with current locale
9+ */
10+ export function Link ( { href, ...props } : ComponentProps < typeof NextLink > ) {
11+ const { locale } = useLingoContext ( ) ;
12+
13+ // If href is already locale-prefixed or external, use as-is
14+ const localizedHref = typeof href === "string" && ! href . startsWith ( "http" ) && ! href . startsWith ( `/${ locale } ` )
15+ ? `/${ locale } ${ href . startsWith ( "/" ) ? "" : "/" } ${ href } `
16+ : href ;
17+
18+ return < NextLink href = { localizedHref } { ...props } /> ;
19+ }
You can’t perform that action at this time.
0 commit comments