All quizzesMedium
API Routes & Middleware
Preview — 3 of 10 questions
What are the three types of dynamic segments in the App Router?
javascript
app/blog/[slug]/page.tsx → ?
app/shop/[...path]/page.tsx → ?
app/docs/[[...path]]/page.tsx → ?AThey all match the same URLs
B[...path] matches exactly two segments
C[[...path]] is a syntax error in Next.js
D[slug] matches a single segment; [...path] matches one or more segments (the parent path itself does not match); [[...path]] is an optional catch-all that matches zero or more segments, so the parent path matches too
What do parentheses in a folder name mean?
javascript
app/(marketing)/page.tsx → URL: /
app/(app)/dashboard/page.tsx → URL: /dashboardA(marketing) adds a /marketing segment to the URL
B(marketing) makes every route inside it auth-protected automatically
CParentheses create a Route Group — the folder is omitted from the URL, so you can organise files and give different sections their own layout.tsx without changing the paths
DRoute groups are a Pages Router feature only
Where does Next.js Middleware run, and what can it do?
javascript
// middleware.ts (project root)
export function middleware(request: NextRequest) { /* ... */ }
export const config = { matcher: ['/dashboard/:path*'] };AIt runs on the server before a request reaches your routes — typically in the Edge runtime — and can read and rewrite the request, redirect, set cookies and headers, or short-circuit with a response; it executes for every request matched by config.matcher
BIt runs in the browser after the page has loaded
CIt only runs for API routes, never for pages
DIt replaces layout.tsx for authentication
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.