Skip to content

Commit 6049a6d

Browse files
committed
refactor: navigation imports to use I18nNavigation for i18n
1 parent d233f64 commit 6049a6d

File tree

9 files changed

+17
-11
lines changed

9 files changed

+17
-11
lines changed
Lines changed: 1 addition & 0 deletions
Loading

src/app/[locale]/(auth)/dashboard/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { SignOutButton } from '@clerk/nextjs';
22
import { getTranslations, setRequestLocale } from 'next-intl/server';
3-
import Link from 'next/link';
43
import { LocaleSwitcher } from '@/components/LocaleSwitcher';
4+
import { Link } from '@/libs/I18nNavigation';
55
import { BaseTemplate } from '@/templates/BaseTemplate';
66

77
export default async function DashboardLayout(props: {

src/app/[locale]/(marketing)/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getTranslations, setRequestLocale } from 'next-intl/server';
2-
import Link from 'next/link';
32
import { DemoBanner } from '@/components/DemoBanner';
43
import { LocaleSwitcher } from '@/components/LocaleSwitcher';
4+
import { Link } from '@/libs/I18nNavigation';
55
import { BaseTemplate } from '@/templates/BaseTemplate';
66

77
export default async function Layout(props: {

src/app/[locale]/(marketing)/portfolio/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Metadata } from 'next';
22
import { getTranslations, setRequestLocale } from 'next-intl/server';
33
import Image from 'next/image';
4-
import Link from 'next/link';
4+
import { Link } from '@/libs/I18nNavigation';
55

66
type IPortfolioProps = {
77
params: Promise<{ locale: string }>;

src/components/CounterForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import { zodResolver } from '@hookform/resolvers/zod';
44
import { useTranslations } from 'next-intl';
5-
import { useRouter } from 'next/navigation';
65
import { useForm } from 'react-hook-form';
6+
import { useRouter } from '@/libs/I18nNavigation';
77
import { CounterValidation } from '@/validations/CounterValidation';
88

99
export const CounterForm = () => {

src/components/DemoBanner.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Link from 'next/link';
1+
import { Link } from '@/libs/I18nNavigation';
22

33
export const DemoBanner = () => (
44
<div className="sticky top-0 z-50 bg-gray-900 p-4 text-center text-lg font-semibold text-gray-100 [&_a]:text-fuchsia-500 [&_a:hover]:text-indigo-500">

src/components/LocaleSwitcher.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
import type { ChangeEventHandler } from 'react';
44
import { useLocale } from 'next-intl';
5-
import { useRouter } from 'next/navigation';
6-
import { usePathname } from '@/libs/I18nNavigation';
5+
import { usePathname, useRouter } from '@/libs/I18nNavigation';
76
import { routing } from '@/libs/I18nRouting';
87

98
export const LocaleSwitcher = () => {
@@ -12,8 +11,14 @@ export const LocaleSwitcher = () => {
1211
const locale = useLocale();
1312

1413
const handleChange: ChangeEventHandler<HTMLSelectElement> = (event) => {
15-
router.push(`/${event.target.value}${pathname}`);
16-
router.refresh(); // Ensure the page takes the new locale into account related to the issue #395
14+
const newLocale = event.target.value;
15+
16+
if (newLocale === locale) {
17+
return;
18+
}
19+
20+
const { search } = window.location;
21+
router.push(`${pathname}${search}`, { locale: newLocale, scroll: false });
1722
};
1823

1924
return (

src/components/Sponsors.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export const Sponsors = () => (
8181
<td className="border-2 border-gray-300 p-3">
8282
<a href="https://posthog.com/?utm_source=github&utm_medium=sponsorship&utm_campaign=next-js-boilerplate">
8383
<Image
84-
src="https://posthog.com/brand/posthog-logo.svg"
84+
src="/assets/images/posthog-logo.svg"
8585
alt="PostHog"
8686
width={260}
8787
height={224}

src/libs/I18nNavigation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import { createNavigation } from 'next-intl/navigation';
22
import { routing } from './I18nRouting';
33

4-
export const { usePathname } = createNavigation(routing);
4+
export const { Link, usePathname, useRouter } = createNavigation(routing);

0 commit comments

Comments
 (0)