next/link component.usePathname() hook.<a> element를 사용하는 것이다. 하지만, 이 방법은 전체 페이지가 refresh새로고침되는 문제점이 있다.
<Link /> 컴포넌트를 사용하여 앱내 페이지 간의 연결을 구현한다. <Link> 컴포넌트는 JavaScript를 이용한 client-side navigation을 가능하게 해주기 때문에, 페이지 전체가 새로고침 되는 것을 방지할 수 있다.
/app/ui/dashboard/nav-links.tsx 파일에 next/link를 import하여 Link 컴포넌트를 사용해보자. (기본 <a>태그를 <Link>로 대체하면 된다)
import {
UserGroupIcon,
HomeIcon,
DocumentDuplicateIcon,
} from '@heroicons/react/24/outline';
**import Link from 'next/link';**
// Map of links to display in the side navigation.
// Depending on the size of the application, this would be stored in a database.
const links = [
{ name: 'Home', href: '/dashboard', icon: HomeIcon },
{
name: 'Invoices',
href: '/dashboard/invoices',
icon: DocumentDuplicateIcon,
},
{ name: 'Customers', href: '/dashboard/customers', icon: UserGroupIcon },
];
export default function NavLinks() {
return (
<>
{links.map((link) => {
const LinkIcon = link.icon;
return (
**<Link
key={link.name}
href={link.href}
className="flex h-[48px] grow items-center justify-center gap-2 rounded-md bg-gray-50 p-3 text-sm font-medium hover:bg-sky-100 hover:text-blue-600 md:flex-none md:justify-start md:p-2 md:px-3"
>**
<LinkIcon className="w-6" />
<p className="hidden md:block">{link.name}</p>
**</Link>**
);
})}
</>
);
}
Next.js는 navigation experience를 개선하기 위해 route segments에 따라 앱을 code split 한다고 한다. 이 말은 코드를 분리된 번들로 쪼개어 독립적으로 로딩할 수 있도록 만든다는 뜻으로, 브라우저가 최초 로딩 시에 모든 앱 코드를 로딩하는 전통적인 React SPA 방식과는 다르다.
여기에 더해, production에서 브라우저 viewport 내에 <Link> 컴포넌트가 나타나게 된다면 Next.js는 자동적으로 해당 linked route의 코드를 백그라운드에서 prefetch한다고 한다.
더 자세한 내용은 아래 참고.

정답: C