install
source · Clone the upstream repo
git clone https://github.com/Intense-Visions/harness-engineering
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/Intense-Visions/harness-engineering "$T" && mkdir -p ~/.claude/skills && cp -r "$T/agents/skills/claude-code/next-app-router" ~/.claude/skills/intense-visions-harness-engineering-next-app-router-2cafe2 && rm -rf "$T"
manifest:
agents/skills/claude-code/next-app-router/SKILL.mdsource content
Next.js App Router
Structure Next.js 13+ applications using the App Router's file-system conventions for layouts, nested routes, and route segments
When to Use
- Starting a new Next.js project with version 13 or later
- Migrating from the Pages Router to the App Router
- Adding nested layouts, route groups, or parallel routes
- Designing URL structures that share UI across multiple routes
- Working with
directory conventions (app/
,layout.tsx
,page.tsx
,loading.tsx
)error.tsx
Instructions
- Place all routes under
. Each folder becomes a route segment;app/
makes it publicly accessible.page.tsx - Use
to wrap route segments in shared UI — layouts persist across navigations and do not re-render.layout.tsx - Create route groups with
to organize routes without affecting the URL path.(groupName)/ - Use
for dynamic segments and[slug]
for catch-all segments. Access params via the[...catchAll]
prop inparams
andpage.tsx
.layout.tsx - Co-locate
alongsideloading.tsx
to stream a Suspense fallback during data fetching.page.tsx - Co-locate
as a Client Component to catch runtime errors within the segment.error.tsx - Use
to render 404 UI and callnot-found.tsx
fromnotFound()
to trigger it.next/navigation - Use
instead oftemplate.tsx
when you need fresh state on every navigation (e.g., page-transition animations).layout.tsx - Prefer route groups to share layouts across unrelated URL paths without creating a shared parent segment.
- Keep
Server Components by default; only addlayout.tsx
if the layout needs interactivity.'use client'
// app/dashboard/layout.tsx — shared layout for all /dashboard/* routes export default function DashboardLayout({ children }: { children: React.ReactNode }) { return ( <div className="flex"> <DashboardNav /> <main className="flex-1">{children}</main> </div> ); } // app/dashboard/[teamId]/page.tsx — dynamic route segment export default function TeamPage({ params }: { params: { teamId: string } }) { return <h1>Team {params.teamId}</h1>; }
Details
The App Router replaces the Pages Router's
getServerSideProps / getStaticProps model with React Server Components and async components. Every file in app/ is a Server Component by default.
File conventions:
page.tsx (route UI), layout.tsx (shared wrapper), loading.tsx (Suspense fallback), error.tsx (error boundary), not-found.tsx (404), route.ts (API endpoint), template.tsx (per-navigation layout), default.tsx (parallel route fallback).
Route groups
(groupName)/ exist only in the filesystem — they do not appear in the URL. Use them to co-locate files without coupling the URL structure.
Trade-offs:
- Layouts cannot read search params — use
prop insearchParams
insteadpage.tsx
is not re-mounted on navigation within its segment, so component state persists; uselayout.tsx
if fresh state is neededtemplate.tsx- Deeply nested layouts increase the React component tree depth — profile rendering if performance degrades
Migration from Pages Router: Pages under
pages/ continue to work alongside app/ — the two routers coexist during migration. Remove a page from pages/ only after its app/ equivalent is tested.
Source
https://nextjs.org/docs/app/building-your-application/routing
Process
- Read the instructions and examples in this document.
- Apply the patterns to your implementation, adapting to your specific context.
- Verify your implementation against the details and edge cases listed above.
Harness Integration
- Type: knowledge — this skill is a reference document, not a procedural workflow.
- No tools or state — consumed as context by other skills and agents.
Success Criteria
- The patterns described in this document are applied correctly in the implementation.
- Edge cases and anti-patterns listed in this document are avoided.