-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathnavigation.tsx
More file actions
27 lines (21 loc) · 826 Bytes
/
navigation.tsx
File metadata and controls
27 lines (21 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { createNavigation } from "@i18next-toolkit/nextjs-approuter/navigation";
import {
forwardRef,
type ComponentPropsWithoutRef,
} from "react";
import { i18nConfig } from "../i18n.config";
import { isExternalHref } from "./navigation-utils";
const navigation = createNavigation(i18nConfig);
const BaseLink = navigation.Link;
type BaseLinkProps = ComponentPropsWithoutRef<typeof BaseLink>;
type LinkProps = BaseLinkProps & ComponentPropsWithoutRef<"a">;
export const Link = forwardRef<HTMLAnchorElement, LinkProps>(
({ href, ...props }, ref) => {
if (typeof href === "string" && isExternalHref(href)) {
return <a ref={ref} href={href} {...props} />;
}
return <BaseLink ref={ref} href={href} {...props} />;
},
);
Link.displayName = "Link";
export const { redirect, usePathname, useRouter } = navigation;