Skip to content
Chapter 29Lesson 7

Quiz - File-system routing with the App Router

Quiz progress

0 / 0

A bare revenue-chart.tsx next to your page.tsx is already non-routable — Next.js never turns a stray component file into a URL. So why does the course still insist you tuck co-located code under a _components/ or _lib/ folder?

Because Next.js keeps reserving new filenames, and a file you named default.tsx or template.tsx would silently become a framework convention — a _-prefixed folder is off the router’s radar entirely, so it can never collide.
Because a bare component file is routable and would leak as a broken page at /dashboard/revenue-chart until you prefix it.
Because the @/ import alias only resolves files that live inside an underscore-prefixed folder.

A dashboard’s sidebar — including its collapsed/expanded toggle and scroll position — lives in a Client Component inside app/(app)/layout.tsx. The page itself holds a half-typed form. The user navigates from /dashboard to /dashboard/settings. What survives the navigation? Select all that apply.

The sidebar’s collapsed/expanded state — the layout stays mounted across navigations within its subtree.
The sidebar’s scroll position — same reason; the layout never unmounted.
The half-typed form text — pages re-render but never fully unmount on navigation.
Nothing — every soft navigation rebuilds the whole tree from the root down.

An invoice detail page sits at app/invoices/[id]/page.tsx, and ids are UUIDs. A senior reviewer rejects a version that does const invoice = await getInvoice((await params).id) directly. What’s the load-bearing fix?

Validate first: safeParse the awaited params against z.object({ id: z.uuid() }), call notFound() on failure, and only pass parsed.data.id to the query — the URL is untrusted input.
Wrap the query in try/catch so a malformed id is caught and rendered as an error page instead of crashing.
Coerce the id with Number(params.id) before querying so a non-UUID string can’t reach the database.

A Server Component runs if (!session) redirect('/sign-in'), then return <Dashboard userId={session.userId} />. A teammate wraps the whole thing in a try/catch “to be safe.” What goes wrong?

The catch swallows the redirect signal — redirect() works by throwing, so a broad catch eats it and the protected page renders for a signed-out user instead of bouncing them.
Nothing goes wrong; wrapping redirect() in try/catch is the recommended way to handle the no-session branch cleanly.
The return line throws because session is null, so you must assign const result = redirect(...) and return that instead.

You build a list-plus-detail invoices screen with a @detail slot and ship it. Clicking around in dev works flawlessly, but a user who opens a shared /invoices/42 link in a fresh tab gets a full-page 404. What did you forget, and why did dev never catch it?

A default.tsx in the @detail slot. Soft navigation carries the previous slot match forward, but a hard load resolves every slot from the URL — an unmatched slot with no fallback 404s the whole route, and dev only ever soft-navigates.
A loading.tsx in the @detail slot — without it the slot can’t stream on a fresh load and the route times out into a 404.
The @detail folder should have been named (detail) — the @ prefix isn’t a valid route group, so it 404s on direct visits.

A dashboard nests everything under a (dashboard) route group. Settings lives at app/(dashboard)/settings/page.tsx (URL /settings) and members at app/(dashboard)/members/page.tsx (URL /members). You add an intercepter at app/(dashboard)/settings/@panel/‹prefix›members/[id]/page.tsx so clicking a row in settings opens the member view as a panel over it. Which prefix is correct?

(..) — the count is URL-segment-relative, and both @panel (a slot) and (dashboard) (a route group) contribute no URL segment, so /settings and /members are just one segment apart.
(..)(..) — walk two folders up the disk tree, past @panel and settings, to reach the members route.
(...) — root the count at the (dashboard) group, since everything lives under it.

Quiz complete

Score by topic