refactor: update locale navigation hooks and imports

- Rename `usePathname` and `useRouter` to `useLocalePathname` and `useLocaleRouter`
- Update imports in locale selector component to use new navigation hook names
- Improve type safety and consistency in internationalization routing
This commit is contained in:
javayhu 2025-03-08 00:59:58 +08:00
parent d6a230a2dc
commit 8199a07674
2 changed files with 10 additions and 5 deletions

View File

@ -7,7 +7,7 @@ import {
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { usePathname, useRouter } from "@/i18n/navigation";
import { useLocalePathname, useLocaleRouter } from "@/i18n/navigation";
import {
DEFAULT_LOCALE,
Locale,
@ -30,8 +30,8 @@ import { useEffect, useTransition } from "react";
* https://next-intl.dev/docs/routing/navigation#userouter
*/
export default function LocaleSelector() {
const router = useRouter();
const pathname = usePathname();
const router = useLocaleRouter();
const pathname = useLocalePathname();
const params = useParams();
const locale = useLocale();
const { currentLocale, setCurrentLocale } = useLocaleStore();

View File

@ -6,5 +6,10 @@ import { routing } from "./routing";
*
* https://next-intl.dev/docs/routing/navigation
*/
export const { Link: LocaleLink, getPathname: getLocalePathname, redirect, usePathname, useRouter } =
createNavigation(routing);
export const {
Link: LocaleLink,
getPathname: getLocalePathname,
redirect: localeRedirect,
usePathname: useLocalePathname,
useRouter: useLocaleRouter
} = createNavigation(routing);