Routing Architecture & Design Review
Knowing every routing convention is not enough. Senior Next.js work is deciding which convention should own which responsibility and keeping the route tree understandable as the product grows.
This chapter turns the Phase 2 primitives into an architecture review method.
The route tree is an executable architecture mapβ
Given:
app/
βββ layout.tsx
βββ (public)/
β βββ layout.tsx
β βββ page.tsx
β βββ pricing/
β β βββ page.tsx
β βββ blog/
β βββ [slug]/
β βββ page.tsx
βββ (product)/
βββ layout.tsx
βββ dashboard/
βββ _components/
βββ loading.tsx
βββ error.tsx
βββ page.tsx
βββ projects/
β βββ [projectId]/
β βββ not-found.tsx
β βββ page.tsx
βββ @activity/
βββ default.tsx
βββ page.tsx
You can infer important behavior before reading implementation code:
- public and product routes are logically grouped
- both still share the top-level root document
- product chrome is scoped to one route group
- dashboard owns loading/error fallback
- project detail is dynamic and owns missing-resource UI
- activity is a named parallel slot
- route-local implementation can live in
_components
A good route tree communicates product structure.
Review dimension 1: URL designβ
Start with public URLs, not folders.
Ask:
- Which URLs are user-facing contracts?
- Which identifiers belong in the path?
- Which values belong in query parameters instead?
- Which routes should be bookmarkable?
- Which routes require hierarchical catch-all paths?
- Are route group names accidentally being treated as URL prefixes?
Example:
/projects/[projectId]/issues/[issueId]
communicates resource hierarchy better than:
/[...slug]
with custom parsing.
Prefer explicit route shapes when the domain is explicit.
Review dimension 2: shared UI ownershipβ
For every layout, ask:
Which descendant routes genuinely share this UI and should preserve it across navigation?
A dashboard sidebar belongs at the dashboard branch.
A project switcher may belong at the project-area branch.
A billing tab bar belongs at billing.
The root layout should own only truly document/global concerns.
Smell: root layout with pathname branchesβ
If the root layout contains many route checks, the filesystem likely is not expressing route ownership clearly enough.
Prefer nested layouts or route groups.
Review dimension 3: persistence vs resetβ
For shared UI, classify state:
Should preserve across sibling routes β layout
Should intentionally reset on segment change β template
Do not add template.tsx until you can name the state/effect/DOM identity that should reset.
Do not move everything into a persistent layout just to avoid rerenders.
Route identity should match product identity.
Review dimension 4: failure ownershipβ
For every branch, identify:
- expected not-found cases
- unexpected failures
- slow work
- slot recovery on hard reload
Then place:
loading.tsxerror.tsxnot-found.tsxdefault.tsx
at the narrowest useful boundary.
Too broadβ
A root loading.tsx that replaces the entire app for one slow dashboard query.
Betterβ
A dashboard or slot-level loading boundary that keeps useful navigation/UI interactive.
Review dimension 5: soft vs hard navigationβ
Advanced App Router behavior often changes depending on navigation type.
Always test both:
Soft navigationβ
<Link>or router-driven client transition- shared layouts can persist
- parallel slots preserve active subpages
- intercepting routes can render contextual overlays
Hard navigationβ
- direct URL
- refresh
- external entry
- cross-root-layout document load
Hard navigation must reconstruct state from the URL and route tree.
This is why:
default.tsxmatters- intercepted routes need real full-page destinations
- multiple roots create full reload boundaries
If a feature only works after arriving through one exact client-navigation sequence, it is usually not robust enough.
Review dimension 6: dynamic parameter trustβ
Every dynamic segment is untrusted input.
/organisations/[organisationId]/projects/[projectId]
requires more than TypeScript.
Review:
- parameter shape validation
- resource existence
- tenant relationship
- current user's membership
- action-level permission
- cache isolation later in the data layer
Never make this assumption:
URL says organisation A
therefore user can access organisation A
Routing locates resources. Authorization proves access.
Review dimension 7: route complexity budgetβ
Not every UI needs an advanced router feature.
Use ordinary components whenβ
- content is simply displayed together
- modal state is transient
- no deep link is needed
- no independent route state exists
Use Parallel Routes whenβ
- independently navigable regions matter
- regions need independent loading/error boundaries
- slot state should persist across soft navigation
- intercepted overlays need a composition target
Use Intercepting Routes whenβ
- a destination needs contextual presentation during soft navigation
- the same URL must work as a full page on direct entry
Architecture is choosing the simplest routing primitive that preserves product semantics.
Case study: SaaS dashboard
Requirements:
- marketing home and pricing
- authenticated dashboard
- project detail routes
- activity panel that can fail independently
- project detail drawer that is shareable
- settings pages under each project
Possible structure:
app/
βββ layout.tsx
βββ (marketing)/
β βββ layout.tsx
β βββ page.tsx
β βββ pricing/
β βββ page.tsx
βββ (app)/
βββ layout.tsx
βββ dashboard/
βββ layout.tsx
βββ page.tsx
βββ @activity/
β βββ default.tsx
β βββ error.tsx
β βββ page.tsx
βββ @drawer/
β βββ default.tsx
β βββ [...catchAll]/
β β βββ page.tsx
β βββ (.)projects/
β βββ [projectId]/
β βββ page.tsx
βββ projects/
βββ page.tsx
βββ [projectId]/
βββ layout.tsx
βββ not-found.tsx
βββ page.tsx
βββ settings/
βββ page.tsx
This is only one design, but it illustrates how primitives compose.
Why not separate root layouts here?β
Marketing and product have different shells, but a shared top-level root can keep transitions in one document tree.
If the organisation intentionally wanted hard document transitions between those experiences, multiple roots might be appropriate.
The routing decision should follow product behavior rather than aesthetics alone.
Case study: documentation platform
Requirements:
- deeply nested docs paths
- one docs shell
- arbitrary nested slugs
- missing pages return route-specific not-found UI
Possible structure:
app/
βββ docs/
βββ layout.tsx
βββ not-found.tsx
βββ [[...slug]]/
βββ page.tsx
An optional catch-all makes /docs and nested documentation paths part of one route model.
This is a good use of catch-all routing because the domain itself is a hierarchical content tree.
Case study: ecommerce product quick view
Requirements:
- product cards on
/shop - clicking a product opens a quick-view modal
- product URL is shareable
- refresh shows full product page
- Back closes quick view
Route-driven modal fit:
app/
βββ shop/
β βββ page.tsx
βββ products/
β βββ [productId]/
β βββ page.tsx
βββ @modal/
βββ default.tsx
βββ [...catchAll]/
β βββ page.tsx
βββ (...)products/
βββ [productId]/
βββ page.tsx
The exact interception matcher depends on the logical route-segment relationship. Count segments, not filesystem folders.
Route-tree anti-patterns
One catch-all as the entire applicationβ
app/[[...path]]/page.tsx
then custom dispatch logic for every product area.
This throws away much of the App Router's explicit architecture.
Use it only when the domain truly requires open-ended paths.
Route groups as imaginary URL namespacesβ
(admin)/users
does not produce /admin/users.
If /admin belongs in the URL, create an admin segment.
Parallel routes for simple grid layoutβ
Two dashboard cards do not automatically need two route slots.
Routing primitives are for navigation/state boundaries, not CSS layout.
Templates used to βfix stale stateββ
A remount can hide an ownership bug. Determine whether state should reset before forcing identity reset.
Missing hard-navigation testsβ
An intercepted modal that works only after clicking from a feed is incomplete if the shared URL fails on refresh.
Missing slot defaultsβ
Parallel routes need deliberate hard-load fallback states. Production builds should catch these issues before deployment.
Debugging route mismatches
When the wrong UI renders, build a route table.
Example:
| Path | Expected page | Layouts | Slots | Special behavior |
|---|---|---|---|---|
/ | home | root + marketing | modal default | normal |
/dashboard | dashboard | root + product + dashboard | activity | normal |
/projects/123 | project | root + product | drawer when intercepted | dynamic param |
Then test each path by:
- direct browser entry
- refresh
<Link>navigation- Back
- Forward
- opening in new tab
This exposes soft/hard differences quickly.
Debugging filesystem confusion
Mark every folder as one of:
URL segment
Dynamic URL segment
Route group
Private folder
Parallel slot
Intercepting route matcher
Ordinary colocated directory
If the team cannot classify the tree confidently, simplify it.
Build-time validation matters
Some App Router mistakes surface most reliably in a production build:
- conflicting routes
- invalid special-file combinations
- missing required parallel slot defaults
- route typing failures
- unsupported module usage
A healthy workflow includes:
npm run build
on every pull request.
Development navigation is not sufficient validation for route architecture.
Design review checklist
Before approving a routing PR, ask:
URLsβ
- Are public URLs stable and understandable?
- Are dynamic values named for domain meaning?
- Is a catch-all actually necessary?
Layoutsβ
- Is shared UI owned by the narrowest correct segment?
- Does persistent state match product expectations?
- Are multiple roots intentional?
Templatesβ
- Can the author name exactly what should reset?
- Would explicit state modelling be simpler?
Groups/private foldersβ
- Are route groups used for organization/layout scope rather than fake URL prefixes?
- Are private folders treated as organization, not security?
Route statesβ
- Are loading/error/not-found boundaries scoped correctly?
- Do missing resources differ from unexpected failures?
Parallel routesβ
- Is independent routing really needed?
- Are all named slot defaults defined?
- Is soft-navigation state preservation understood?
Interceptionβ
- Does the destination work as a full page?
- Is the matcher based on route segments?
- Do Back, Forward, refresh, and direct entry behave correctly?
Securityβ
- Are params validated?
- Is authorization enforced at server/data boundaries?
- Could tenant IDs cross scopes?
Operationsβ
- Does
next buildpass? - Are production-only route failures covered by tests?
Phase 2 milestone project
Build a dashboard with:
/dashboard
/dashboard/projects
/dashboard/projects/[projectId]
/dashboard/projects/[projectId]/settings
Requirements:
- Root site layout.
- Dashboard nested layout.
- Dynamic project route using async
params. - Route-specific
not-found.tsxfor missing projects. - Dashboard
loading.tsxanderror.tsxwith appropriate scope. - A route group used for organization without changing URLs.
- A private
_componentsor_libfolder. - A Parallel Route for activity or notifications with
default.tsx. - A route-driven project preview or login modal using interception.
- Full-page destination works on refresh/direct entry.
- Back/Forward behavior is correct.
- Production build passes.
Explain your architectureβ
You should be able to whiteboard:
URL
β matching route segments
β layouts
β template identity if present
β named slots
β page
β loading/error/not-found boundaries
β hard vs soft navigation behavior
If you can explain the route branch before looking at runtime code, your routing mental model is becoming senior-level.
Phase 2 interview drill
Why is the App Router better understood as a tree than a page list?
Because nested segments compose layouts, route state boundaries, dynamic params, and slots along the selected branch. The rendered screen is the composition of that tree, not only one page file.
What is the biggest architectural cost of multiple root layouts?
Cross-root navigation becomes a full page load because the document root changes.
What is the most common mistake with Intercepting Routes?
Counting filesystem folders instead of route segments, especially when a parallel @slot is involved.
Why must advanced routing be tested with refresh and direct URLs?
Soft navigation can preserve in-memory layout/slot context that does not exist during hard navigation. A robust route must reconstruct a valid UI from the URL and its hard-load fallbacks.
When is a Parallel Route justified?
When a screen region needs routing semanticsβindependent navigation, loading/error state, slot persistence, or contextual interceptionβnot simply because multiple components are visible.
Official referencesβ
- https://nextjs.org/docs/app/getting-started/layouts-and-pages
- https://nextjs.org/docs/app/api-reference/file-conventions
- https://nextjs.org/docs/app/api-reference/file-conventions/parallel-routes
- https://nextjs.org/docs/app/api-reference/file-conventions/intercepting-routes
Phase 2 is complete when you can design, debug, and explain these route relationships without relying on trial and error.
Next phase: Navigation & URL State.