← スキル一覧に戻る

nextjs-server-navigation
by kensleDev
⭐ 0🍴 0📅 2026年1月16日
SKILL.md
name: nextjs-server-navigation
IMPORTANT: Keep description on ONE line for Claude Code compatibility
prettier-ignore
description: Server Component navigation: for links, redirect() for conditional redirects. NO 'use client' needed for static links or server redirects. allowed-tools: Read, Write, Edit, Glob, Grep, Bash
Next.js: Server Component Navigation
Quick Start
Server Components use DIFFERENT methods than Client Components!
| Method | Server Component | Client Component |
|---|---|---|
| Links | <Link> ✅ | <Link> ✅ |
| Redirect | redirect() ✅ | ❌ No |
| Router hook | ❌ No | useRouter() ✅ |
// app/page.tsx - Server Component (NO 'use client'!)
import Link from 'next/link';
export default async function Page() {
const data = await fetchData(); // Can fetch!
return (
<div>
<h1>Welcome</h1>
<Link href="/dashboard">Dashboard</Link>
<Link href={`/products/${data.id}`}>View Product</Link>
</div>
);
}
Conditional Redirect
import { redirect } from 'next/navigation';
export default async function ProfilePage() {
const session = await getSession();
if (!session) redirect('/login'); // Server-side redirect
return <div>Welcome</div>;
}
❌ WRONG - Adding 'use client' for Navigation
// ❌ WRONG
'use client'; // Don't add this just for links!
export default function Page() {
return <Link href="/about">About</Link>;
}
✅ CORRECT - Keep as Server Component
// ✅ CORRECT
import Link from 'next/link';
export default async function Page() {
return <Link href="/about">About</Link>;
}
Notes
- No 'use client' needed:
<Link>andredirect()work in Server Components - useRouter() is client-only: Only for Client Components
- Last verified: 2025-01-11
スコア
総合スコア
40/100
リポジトリの品質指標に基づく評価
✓SKILL.md
SKILL.mdファイルが含まれている
+20
○LICENSE
ライセンスが設定されている
0/10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
○タグ
1つ以上のタグが設定されている
0/5
レビュー
💬
レビュー機能は近日公開予定です