์ž‘๊ฐ€:
    ์ƒ์„ฑ:2026-06-22๋งˆ์ง€๋ง‰ ์—…๋ฐ์ดํŠธ:2026-06-22

    Next.js ํ†ตํ•ฉ: usePathname ํ›… ๋ฌธ์„œ

    usePathname ํ›…์€ ๋กœ์ผ€์ผ ์„ธ๊ทธ๋จผํŠธ๊ฐ€ ์ œ๊ฑฐ๋œ ํ˜„์žฌ Next.js ๊ฒฝ๋กœ ์ด๋ฆ„์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ์ˆ˜๋™์œผ๋กœ ๋กœ์ผ€์ผ ์ ‘๋‘์‚ฌ๋ฅผ ์ œ๊ฑฐํ•˜์ง€ ์•Š๊ณ ๋„ ๋กœ์ผ€์ผ์„ ์ธ์‹ํ•˜๋Š” ํƒ์ƒ‰(์˜ˆ: ์–ด๋–ค ํƒ์ƒ‰ ํ•ญ๋ชฉ์ด ํ™œ์„ฑํ™”๋˜์—ˆ๋Š”์ง€ ํŒ๋‹จ)์„ ๊ตฌ์ถ•ํ•  ๋•Œ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.

    Next.js์—์„œ usePathname ๊ฐ€์ ธ์˜ค๊ธฐ

    typescript
    import { usePathname } from "next-intlayer";
    

    ๊ฐœ์š”

    usePathname์€ next/navigation์˜ ๋‚ด์žฅ usePathname()์„ ๋ž˜ํ•‘ํ•˜์—ฌ ๊ฒ€์ƒ‰ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ  getPathWithoutLocale์„ ํ†ตํ•ด ๋กœ์ผ€์ผ ์ ‘๋‘์‚ฌ๋ฅผ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค. ํด๋ผ์ด์–ธํŠธ ์ธก ํƒ์ƒ‰์ด ๋ฐœ์ƒํ•  ๋•Œ๋งˆ๋‹ค ๋‹ค์‹œ ๋ Œ๋”๋ง๋ฉ๋‹ˆ๋‹ค. ์ด ํ›…์€ ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ์—์„œ๋งŒ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค("use client" ํ•„์š”).

    ์‚ฌ์šฉ๋ฒ•

    src/components/NavItem.tsx
    "use client";
    
    import type { FC } from "react";
    import { usePathname } from "next-intlayer";
    
    type NavItemProps = {
      href: string;
      label: string;
    };
    
    const NavItem: FC<NavItemProps> = ({ href, label }) => {
      const pathname = usePathname();
      const isActive = pathname === href;
    
      return (
        <a href={href} aria-current={isActive ? "page" : undefined}>
          {label}
        </a>
      );
    };
    
    export default NavItem;
    

    ๋ฐ˜ํ™˜ ๊ฐ’

    ์œ ํ˜•์„ค๋ช…
    string๋กœ์ผ€์ผ ์ ‘๋‘์‚ฌ์™€ ๋กœ์ผ€์ผ ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ์ œ๊ฑฐ๋œ ์ฟผ๋ฆฌ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์ œ์™ธํ•œ ํ˜„์žฌ ๊ฒฝ๋กœ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.

    ๋™์ž‘ ๋ฐฉ์‹

    • ๋กœ์ผ€์ผ ์ œ๊ฑฐ: ์„ ํ–‰ ๋กœ์ผ€์ผ ์„ธ๊ทธ๋จผํŠธ๋ฅผ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค(์˜ˆ: /ko/dashboard โ†’ /dashboard).
    • ๊ฒ€์ƒ‰ ๋งค๊ฐœ๋ณ€ ์ œ๊ฑฐ: ๊ฒ€์ƒ‰ ๋งค๊ฐœ๋ณ€์ˆ˜ ๊ธฐ๋ฐ˜ ๋ผ์šฐํŒ… ๋ชจ๋“œ๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ?locale=... ์ฟผ๋ฆฌ ๋งค๊ฐœ๋ณ€์ˆ˜๋„ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค.
    • ๋ฐ˜์‘ํ˜•: Next.js App Router๋ฅผ ํ†ตํ•œ ๋ชจ๋“  ํด๋ผ์ด์–ธํŠธ ์ธก ํƒ์ƒ‰ ์‹œ ์ž๋™์œผ๋กœ ์—…๋ฐ์ดํŠธ๋ฉ๋‹ˆ๋‹ค.
    • SSR-์•ˆ์ „: ์ฒซ ๋ Œ๋”๋ง ์‹œ์—๋Š” ์„œ๋ฒ„ ์ธก ๊ฒฝ๋กœ ์ด๋ฆ„์„ ๋ฐ˜ํ™˜ํ•œ ํ›„ ํด๋ผ์ด์–ธํŠธ์—์„œ ๊ฒ€์ƒ‰ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ๋™๊ธฐํ™”ํ•ฉ๋‹ˆ๋‹ค.

    useLocale๊ณผ์˜ ๋น„๊ต

    next-intlayer์˜ useLocale์€ ์ด๋ฏธ ๋ฐ˜ํ™˜ ๊ฐ’์˜ ์ผ๋ถ€๋กœ pathWithoutLocale์„ ๋…ธ์ถœํ•ฉ๋‹ˆ๋‹ค. ๊ฒฝ๋กœ๋งŒ ํ•„์š”ํ•˜๊ณ  ๋กœ์ผ€์ผ ์ „ํ™˜ ๊ธฐ๋Šฅ์ด ํ•„์š”ํ•˜์ง€ ์•Š์€ ๊ฒฝ์šฐ usePathname์„ ์‚ฌ์šฉํ•˜์„ธ์š”.

    tsx
    // ๋กœ์ผ€์ผ ์ƒํƒœ์™€ ๊ฒฝ๋กœ๊ฐ€ ๋ชจ๋‘ ํ•„์š”ํ•  ๋•Œ:
    import { useLocale } from "next-intlayer";
    const { locale, pathWithoutLocale } = useLocale();
    
    // ๊ฒฝ๋กœ๋งŒ ํ•„์š”ํ•  ๋•Œ:
    import { usePathname } from "next-intlayer";
    const pathname = usePathname();
    

    ์˜ˆ์‹œ

    src/components/Sidebar.tsx
    "use client";
    
    import type { FC } from "react";
    import { usePathname } from "next-intlayer";
    
    const links = [
      { href: "/dashboard", label: "๋Œ€์‹œ๋ณด๋“œ" },
      { href: "/settings", label: "์„ค์ •" },
    ];
    
    const Sidebar: FC = () => {
      const pathname = usePathname();
    
      return (
        <nav>
          {links.map(({ href, label }) => (
            <a
              key={href}
              href={href}
              style={{ fontWeight: pathname === href ? "bold" : "normal" }}
            >
              {label}
            </a>
          ))}
        </nav>
      );
    };
    
    export default Sidebar;
    

    ๊ด€๋ จ

    • useLocale โ€” ํ˜„์žฌ ๋กœ์ผ€์ผ + ๋กœ์ผ€์ผ ์Šค์œ„์ฒ˜ (pathWithoutLocale๋„ ๋…ธ์ถœ)
    • getPathWithoutLocale โ€” ์ด ํ›…์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๊ธฐ๋ณธ ์œ ํ‹ธ๋ฆฌํ‹ฐ