Communitygithub.com

ComeOnOliver/skillshub

Next.js App Router タスク(ページ作成、動的ルーティング、ネストレイアウト、サーバー/クライアントコンポーネント最適化、ERPロールベースページ)に使用します。/app/ ディレクトリ操作、動的ルーティング、App Router固有機能で自動的に使用されます。

skillshub とは?

このスキルは、Next.js App Router を使用した開発全般を支援するエキスパートガイドです。主な機能として、/app/ ディレクトリ内のページ作成、動的ルーティング ([id]/page.tsx)、ネストされたレイアウトとテンプレート (layout.tsx、template.tsx)、サーバーコンポーネントとクライアントコンポーネントの最適化、そして教育機関向けERPシステムのようなロールベースのダッシュボード(管理者、教師、学生)の構築をサポートします。このスキルは、Claude Code や Cursor などの AI エージェントが Next.js プロジェクトで作業する際に特に有用で、TypeScript の厳格な型チェック、SEO のための generateMetadata()、Suspense を使用した非同期データ取得のローディング状態、error.tsx によるエラーハンドリングといったベストプラクティスを強制します。また、shadcn/ui の統合や、Recharts を使用した KPI チャートの作成方法も網羅しており、高品質で保守性の高い Next.js アプリケーションを効率的に開発できます。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ComeOnOliver/skillshub/tree/HEAD/skills/aiskillstore/marketplace/awais68/frontend-nextjs-app-router

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Next.js App Router エキスパート

概要

Next.js App Router 開発に関するエキスパートガイド: ページ作成、動的ルーティング、ネストレイアウト、サーバー/クライアントコンポーネントの最適化、ERPロールベースのダッシュボードを網羅します。

コア機能

1. ページ作成 (/app/.../page.tsx)

ルール:

  • デフォルトで サーバーコンポーネント を使用 ('use client' ディレクティブは使用しない)
  • fetch() または ORM クエリによる非同期データ取得を直接記述
  • 初期データロードに useEffect を使用しない
  • ローディング状態には Suspense バウンダリを使用
  • generateMetadata() による SEO メタデータ

テンプレート:

// app/dashboard/page.tsx
import { Suspense } from 'react';
import { TaskList } from '@/components/TaskList';
import { TaskListSkeleton } from '@/components/TaskListSkeleton';

export const metadata = {
  title: 'ダッシュボード',
  description: 'タスク管理ダッシュボード',
};

export default async function DashboardPage() {
  const tasks = await fetchTasks();

  return (
    <main className="p-4">
      <h1>ダッシュボード</h1>
      <Suspense fallback={<TaskListSkeleton />}>
        <TaskList initialTasks={tasks} />
      </Suspense>
    </main>
  );
}

2. 動的ルート ([slug]/page.tsx)

使用場面:

  • 学生プロフィール: app/students/[studentId]/page.tsx
  • タスク詳細: app/tasks/[taskId]/page.tsx
  • コースページ: app/courses/[courseId]/page.tsx

ルール:

  • params プロパティからパラメータを抽出 (読み取り専用)
  • SEO のために generateMetadata() を使用
  • not-found.tsx で 404 を処理

テンプレート:

// app/students/[studentId]/page.tsx
import { notFound } from 'next/navigation';

type Params = Promise<{ studentId: string }>;

export async function generateMetadata({ params }: { params: Params }) {
  const { studentId } = await params;
  const student = await getStudent(studentId);

  if (!student) return { title: '学生が見つかりません' };

  return {
    title: `${student.name} - 学生プロフィール`,
  };
}

export default async function StudentProfile({ params }: { params: Params }) {
  const { studentId } = await params;
  const student = await getStudent(studentId);

  if (!student) notFound();

  return <StudentProfileView student={student} />;
}

3. パラレルルート (@フォルダ)

使用場面:

  • ダッシュボードのバリエーション: app/dashboard@(admin|teacher)/page.tsx
  • 分割レイアウト: app/settings@(user|organization)/layout.tsx

テンプレート:

// app/dashboard/@admin/page.tsx - 管理者ダッシュボード
export default function AdminDashboard() {
  return <AdminPanel />;
}

// app/dashboard/@teacher/page.tsx - 教師ダッシュボード
export default function TeacherDashboard() {
  return <TeacherPanel />;
}

4. レイアウトとテンプレート

ルートレイアウト (app/layout.tsx):

import { Providers } from '@/components/Providers';
import './globals.css';

export const metadata = {
  title: 'Todo Evolution',
  description: '教育向けタスク管理',
};

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        <Providers>{children}</Providers>
      </body>
    </html>
  );
}

ネストレイアウト (app/dashboard/layout.tsx):

import { DashboardNav } from '@/components/DashboardNav';

export default function DashboardLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <div className="flex min-h-screen">
      <DashboardNav />
      <main className="flex-1 p-6">{children}</main>
    </div>
  );
}

テンプレート (app/tasks/template.tsx):

// ナビゲーション時に再実行、フォーム状態を保持
export default function TasksTemplate({ children }: { children: React.ReactNode }) {
  return (
    <div className="bg-gray-50 min-h-screen">
      <header className="bg-white shadow">
        <h1>タスク</h1>
      </header>
      {children}
    </div>
  );
}

5. サーバーコンポーネント vs クライアントコンポーネント

サーバーコンポーネントを使用する場面:

  • データ取得
  • データベースへの直接クエリ
  • 静的コンテンツ
  • サーバー限定の処理

クライアントコンポーネント ('use client') を使用する場面:

  • ブラウザ API (window, localStorage)
  • イベントハンドラ (onClick, onSubmit)
  • React フック (useState, useEffect)
  • 状態管理 (Zustand, Redux)
  • インタラクティブ性
// サーバーコンポーネント (デフォルト)
export default async function TaskList() {
  const tasks = await fetchTasks(); // 直接DBクエリ
  return <div>{tasks.map(/* ... */)}</div>;
}

// クライアントコンポーネント
'use client';
import { useTaskStore } from '@/store/tasks';

export function TaskFilter() {
  const { filter, setFilter } = useTaskStore();
  return <button onClick={() => setFilter('all')}>すべてのタスク</button>;
}

6. ERP ロールベースページ

ロールガード:

// app/admin/page.tsx
import { requireRole } from '@/lib/auth';
import { redirect } from 'next/navigation';

export default async function AdminPage() {
  const session = await getSession();

  if (session?.role !== 'admin') {
    redirect('/unauthorized');
  }

  return <AdminDashboard />;
}

KPI ダッシュボード (Recharts):

'use client';
import { BarChart, Bar, XAxis, YAxis, Tooltip } from 'recharts';

export function TaskKPIChart({ data }: { data: TaskStats[] }) {
  return (
    <BarChart width={600} height={300} data={data}>
      <XAxis dataKey="date" />
      <YAxis />
      <Tooltip />
      <Bar dataKey="completed" fill="#22c55e" />
    </BarChart>
  );
}

7. エラーとローディング状態

エラーバウンダリ (error.tsx):

'use client';
export default function Error({
  error,
  reset,
}: {
  error: Error & { digest?: string };
  reset: () => void;
}) {
  return (
    <div>
      <h2>問題が発生しました!</h2>
      <button onClick={reset}>再試行</button>
    </div>
  );
}

ローディング状態 (loading.tsx):

export default function Loading() {
  return <div className="animate-pulse">読み込み中...</div>;
}

// または Suspense を使用:
export default async function Page() {
  return (
    <Suspense fallback={<Loading />}>
      <Content />
    </Suspense>
  );
}

8. shadcn/ui 統合

インストール:

npx shadcn@latest add button card input dialog

サーバーコンポーネントでの使用:

import { Button } from '@/components/ui/button';
import { Card, CardContent, CardHeader } from '@/components/ui/card';

export default async function TaskPage() {
  const tasks = await getTasks();

  return (
    <Card>
      <CardHeader>タスク</CardHeader>
      <CardContent>
        {tasks.map(task => (
          <div key={task.id}>{task.title}</div>
        ))}
      </CardContent>
    </Card>
  );
}

ワークフロー決定ツリー

ユーザーリクエスト → 分析 → 実装パス

  1. 「ダッシュボード/管理ページを作成して」 → page.tsx でサーバーコンポーネント → 非同期データ取得 → ナビゲーションが必要な場合は layout.tsx を追加

  2. 「動的な学生プロフィールを」 → [studentId]/page.tsx を作成 → パラメータを抽出 → generateMetadata() を追加 → 必要に応じて not-found.tsx を作成

  3. 「共有レイアウトを追加して」 → 対象フォルダに layout.tsx を作成 → 必要に応じてプロバイダーでラップ → children レンダリングを維持

  4. 「フォームを追加して」 → 'use client' コンポーネント → フォームデータに useState → 送信用にサーバーアクションまたはAPIルート

  5. 「KPIチャート/分析を」 → Recharts 用に 'use client' → データ取得用のサーバーコンポーネント親 → データをプロップとして渡す

品質チェックリスト

タスク完了前に確認:

  • TypeScript の厳格モードが有効
  • デフォルトでサーバーコンポーネントを使用
  • 'use client' は必要な場合のみ
  • SEO 用の generateMetadata()
  • 非同期データ用の Suspense バウンダリ
  • 必要箇所にエラーバウンダリ (error.tsx)
  • ハイドレーション不一致がない
  • パフォーマンス最適化 (ブロックするレンダリングがない)
  • モバイルファーストのレスポンシブデザイン
  • アクセシブル (ARIA ラベル、キーボードナビゲーション)

共通パターン

パターン1: サーバーコンポーネント + クライアントコンポーネントの混合

// サーバーコンポーネント
export default async function Page() {
  const tasks = await fetchTasks();
  return <TaskList tasks={tasks} />; // インタラクティブ性のためにクライアントコンポーネント
}

'use client';
function TaskList({ tasks }: { tasks: Task[] }) {
  const [filter, setFilter] = useState('all');
  const filtered = tasks.filter(/* ... */);
  return <div>{filtered.map(/* ... */)}</div>;
}

パターン2: 整理のためのルートグループ

app/
  (marketing)/     # グループ: URL セグメントなし
    about/page.tsx
    contact/page.tsx
  (dashboard)/      # グループ: URL セグメントなし
    layout.tsx
    page.tsx

パターン3: APIルート (ルートハンドラ)

// app/api/tasks/route.ts
import { NextResponse } from 'next/server';

export async function GET() {
  const tasks = await db.query.tasks.findMany();
  return NextResponse.json(tasks);
}

export async function POST(request: Request) {
  const body = await request.json();
  const task = await createTask(body);
  return NextResponse.json(task, { status: 201 });
}

トリガー例

  • 「ダッシュボードページを作成して」 → サーバーコンポーネントで app/dashboard/page.tsx を生成
  • 「動的な学生プロフィールルートを」 → パラメータとメタデータを持つ app/students/[studentId]/page.tsx
  • 「共有レイアウトを追加して」 → children を持つ app/dashboard/layout.tsx
  • 「チャート付き管理パネルを」 → サーバーコンポーネント + クライアントチャートコンポーネント
  • 「ログインページを作成して」 → 'use client' フォームコンポーネント + APIルート
  • 「404 ページをカスタマイズして」 → app/not-found.tsx
  • 「エラー処理をして」 → app/dashboard/error.tsx

参照

高度なパターンについては references/app-router-patterns.md、ルートハンドラの例については references/api-routes.md を参照してください。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

ComeOnOliver/skillshub

Create stunning, animation-rich HTML presentations from scratch or by converting PowerPoint files. Use when the user wants to build a presentation, convert a PPT/PPTX to web, or create slides for a talk/pitch. Helps non-designers discover their aesthetic through visual exploration rather than abstract choices.

ComeOnOliver/skillshub

Next.js 16+ 和 Turbopack — 增量打包、文件系统缓存、开发速度,以及何时使用 Turbopack 与 webpack。

ComeOnOliver/skillshub

SwiftUI architecture patterns, state management with @Observable, view composition, navigation, performance optimization, and modern iOS/macOS UI best practices.

ComeOnOliver/skillshub

See, Understand, Act on video and audio. See- ingest from local files, URLs, RTSP/live feeds, or live record desktop; return realtime context and playable stream links. Understand- extract frames, build visual/semantic/temporal indexes, and search moments with timestamps and auto-clips. Act- transcode and normalize (codec, fps, resolution, aspect ratio), perform timeline edits (subtitles, text/image overlays, branding, audio overlays, dubbing, translation), generate media assets (image, audio, video), and create real time alerts for events from live streams or desktop capture.

ComeOnOliver/skillshub

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

ComeOnOliver/skillshub

Next.js 15 애플리케이션을 위한 프론트엔드 개발 가이드라인. React 19, TypeScript, Shadcn/ui, Tailwind CSS를 사용한 모던 패턴. Server Components, Client Components, App Router, 파일 구조, Shadcn/ui 컴포넌트, 성능 최적화, TypeScript 모범 사례 포함. 컴포넌트, 페이지, 기능 생성, 데이터 페칭, 스타일링, 라우팅, 프론트엔드 코드 작업 시 사용.

ComeOnOliver/skillshub

Provides Tamagui patterns for config v4, compiler optimization, styled context, and cross-platform styling. Must use when working with Tamagui projects (tamagui.config.ts, @tamagui imports).

ComeOnOliver/skillshub

Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.

ComeOnOliver/skillshub

Create high-converting, visually distinctive landing pages. Use when building marketing pages, product launches, SaaS homepages, or any single-page conversion-focused website. Guides section-by-section composition with anti-AI-slop principles.

ComeOnOliver/skillshub

Auto-loaded context for Portfolio Buddy 2 development. Use for ANY task involving: React 19 development, TypeScript, portfolio analysis features, metrics calculations, trading strategy comparison, or working with the Portfolio Buddy 2 codebase. Contains tech stack, known issues, and architectural constraints.

ComeOnOliver/skillshub

Next.js development tooling via MCP. Inspect routes, components, build info, and debug Next.js apps. Use when working on Next.js applications, debugging routing, or inspecting app structure. NOT for general React or non-Next.js projects.

ComeOnOliver/skillshub

Implement UI using Shadcn MCP (atoms/theme) and 21st.dev MCP (complex sections). Use when adding buttons, layouts, or generating landing pages.

ComeOnOliver/skillshub

A conceptual skill for building an API client in Next.js that handles JWT tokens

ComeOnOliver/skillshub

Best practices and patterns for Next.js App Router, Server Actions, and Routing in this project.

ComeOnOliver/skillshub

The Design System, Theme, and UX rules for the Physical AI Hub.

ComeOnOliver/skillshub

Comprehensive frontend development skill for building modern, performant web applications using ReactJS, NextJS, TypeScript, Tailwind CSS. Includes component scaffolding, performance optimization, bundle analysis, and UI best practices. Use when developing frontend features, optimizing performance, implementing UI/UX designs, managing state, or reviewing frontend code.

ComeOnOliver/skillshub

This document captures learnings from fixing keyboard navigation issues when floating components (Select, DropdownMenu, Popover) have CSS open/close animations.

ComeOnOliver/skillshub

Build Next.js 16 applications with correct patterns and distinctive design. Use when creating pages, layouts, dynamic routes, upgrading from Next.js 15, or implementing proxy.ts. Covers breaking changes (async params/searchParams, Turbopack, cacheComponents) and frontend aesthetics. NOT when building non-React or backend-only applications.

ComeOnOliver/skillshub

Comprehensive Framer Motion animation library for React. Covers motion components, variants, gestures, page transitions, and scroll animations. Use when adding animations to React/Next.js applications.

ComeOnOliver/skillshub

Build interfaces that resonate, not just render. This skill enforces bold, intentional

関連スキル