Navigation Architecture, Debugging & Design Review
A senior engineer does not review navigation by checking whether links click.
They ask whether the routing system has a coherent contract across:
URL design
route tree
server/client boundaries
prefetching
loading feedback
history
scroll/focus
security
analytics
caching
error handling
Phase 3 closes by turning individual APIs into a production navigation architecture.
Start with the URL contractβ
Before choosing hooks, write the public URL shapes.
Example SaaS product:
/dashboard
/projects
/projects/[projectId]
/projects/[projectId]/activity
/projects/[projectId]/settings
/search?query=...&page=...
/settings/profile
/settings/security
A good URL contract is:
- stable
- readable
- shareable
- domain-oriented
- independent from component folder names
- explicit about path state vs query state
The URL is part of your product API.
Path vs query vs local stateβ
Use a path segment when identity/hierarchy matters.
/projects/p_42/settings
Use query state for orthogonal view configuration.
/projects?status=active&sort=updated&page=2
Use local state for ephemeral interaction.
hovered row
open tooltip
uncommitted input draft
A common architecture bug is putting all three categories into React state and rebuilding routing manually.
Navigation ownershipβ
Define who owns each transition.
| Transition | Owner |
|---|---|
| user clicks normal destination | <Link> |
| imperative client interaction | useRouter |
| server discovers user must move | redirect |
| canonical resource permanently moved | permanentRedirect |
| browser shallow URL state update | History API when appropriate |
| route loading feedback | loading.tsx / Suspense |
| link-specific blocked feedback | useLinkStatus |
Architecture becomes easier to reason about when ownership is predictable.
Keep the server/client boundary narrowβ
Bad pattern:
'use client'
export default function DashboardLayout(...) {
// pathname, nav, data, auth, everything
}
Better:
Server Component layout
βββ server-rendered shell
βββ server-owned data/auth where appropriate
βββ ClientActiveNav
βββ children
Only the route-aware interactive piece needs hooks such as usePathname.
This reduces client JavaScript and keeps server capabilities available.
URL state should be one source of truthβ
If a result page is represented by:
/search?query=coffee&page=3
then opening that URL directly should reconstruct the same meaningful view.
If the UI instead depends on hidden React state:
const [page, setPage] = useState(1)
while the URL says page=3, your architecture has two competing truths.
Either derive from the URL or define a clear draft/commit boundary.
Security reviewβ
Navigation code creates several trust boundaries.
Dynamic paramsβ
/organisations/[organisationId]/projects/[projectId]
Identifiers are untrusted route input.
Query paramsβ
?sort=...&returnTo=...&filter=...
These are untrusted request input.
Programmatic destinationsβ
router.push(value)
Must not receive unvalidated arbitrary schemes/destinations.
Hidden linksβ
Not authorization.
Client redirect logicβ
Not a substitute for server enforcement.
A navigation design review should explicitly identify every input that influences a resource or destination.
Performance reviewβ
Do not optimize navigation from folklore.
Measure:
click-to-feedback
click-to-URL-change
click-to-meaningful-content
server route latency
prefetch hit/miss
route payload size
client JS/hydration cost
Then ask:
- Is the destination dynamic unnecessarily?
- Does it need
loading.tsx? - Is prefetch disabled?
- Are thousands of links prefetching unnecessarily?
- Is a client boundary too large?
- Is server data work slow?
- Is the query update generating too many requests?
The router is only one part of the timeline.
Large link surfacesβ
Imagine an infinite-scroll table with 5,000 detail links.
Automatic viewport prefetch can become a resource consideration.
Options include:
- default prefetch where the visible set is small
- deliberate
prefetch={false}for huge surfaces - hover-triggered prefetch for high-intent destinations
- virtualizing the list if rendering itself is expensive
Choose from measurements. Do not globally disable prefetch because one screen is large.
Dynamic-route loading designβ
For a slow dynamic route:
/reports/[reportId]
ask whether the user can receive an immediate shell.
reports layout
β preserved
report loading boundary
β shown quickly
report data/content
β streams/replaces
This often produces better UX than a full-screen progress overlay controlled from the source page.
Query update architectureβ
For filters:
input event
β
normalize local value
β
update URL
β
server/client view derives from URL
For high-frequency input:
keystrokes
β debounce/commit policy
URL replace
β
results refresh
The debounce belongs before expensive navigation/data work.
Preserve meaningful historyβ
Design a user journey:
catalogue
β filter
β product
β Back
What should Back restore?
If the answer is βthe filtered catalogue,β the filter must survive in the URL/history state or another deliberate restoration mechanism.
URL-driven state is often the simplest correct answer.
Navigation and analyticsβ
Do not equate DOM clicks with page views.
A link can be:
- opened in a new tab
- canceled
- superseded by another navigation
- redirected
For page-view analytics, observe the committed route URL.
For interaction analytics, track the user's navigation intent separately.
This separation avoids inflated or misleading metrics.
Navigation and authorizationβ
A robust request path looks like:
URL requested
β
route matched
β
authentication context resolved
β
resource scoped and authorized
β
render or redirect/not-found/forbidden policy
Not:
link visible
β
therefore allowed
The route tree is discoverability and composition. The security model lives at server trust boundaries.
Common failure: hydration mismatch after rewriteβ
Symptom:
server HTML shows source-path-derived UI
client hook reads rewritten browser pathname
React reports mismatch
Debug:
- identify rewrite/proxy behavior
- find UI rendered from pathname
- keep server HTML stable
- isolate client pathname-dependent fragment
- update after mount if necessary
Do not solve by suppressing hydration warnings globally.
Common failure: production build fails around useSearchParamsβ
Symptom:
works in dev
fails in next build
Cause can be a statically prerendered route with useSearchParams() outside an appropriate Suspense boundary.
Fix:
- isolate the client query-reading subtree
- wrap with Suspense
- or intentionally make the route request-time dynamic when that is truly required
The production build is part of routing correctness.
Common failure: Back button feels randomβ
Inspect whether interactions use:
push
replace
native pushState
native replaceState
Write the actual history sequence on paper.
Most βrouter Back is brokenβ bugs are history-policy bugs.
Common failure: active navigation is wrongβ
Potential causes:
- brittle prefix matching
- route group values leaking into breadcrumb logic
- query strings mixed into pathname comparisons
- dynamic route IDs compared to route patterns
- selected segment hook called at wrong layout depth
- parallel route key mismatch
Choose the route signal that matches the UI concept.
Common failure: navigation feels frozenβ
Check in order:
1. link/event handler responsive?
2. prefetch available?
3. loading boundary available?
4. server work slow?
5. network slow?
6. client bundle/hydration heavy?
7. destination render expensive?
Do not add a spinner before finding the stage.
Common failure: duplicate network/server workβ
Possible causes include:
- client fetching data already rendered by the server
- manual prefetch plus automatic prefetch without a reason
- search navigation on every keystroke
- unstable query serialization
- layout/page responsibilities duplicated
Later phases cover data/cache mechanics in detail. For now, navigation should not create redundant ownership.
Debugging toolkitβ
Browser DevTools Networkβ
Inspect:
- route/RSC requests
- timing
- prefetch requests
- duplicate requests
- redirects
React/Next development toolsβ
Use route/static-dynamic indicators and browser/terminal diagnostics where available.
Production buildβ
npm run build
Catches routing/rendering assumptions hidden by development behavior.
Direct URL testingβ
Paste every important URL into a fresh tab.
This catches flows that only work after client navigation.
Slow network simulationβ
Useful for exposing missing loading feedback and prefetch assumptions.
Design review checklistβ
URL designβ
- URLs represent domain concepts.
- Shareable state is in the URL where appropriate.
- Path vs query choices are deliberate.
- Defaults/canonical forms are defined.
Navigation APIsβ
- Normal navigation uses
<Link>. - Imperative navigation has a real client-event reason.
- Server-known redirect decisions stay on the server.
- Push vs replace is product-driven.
Performanceβ
- Prefetch policy is measured.
- Dynamic routes have useful loading boundaries.
- Large link lists have an intentional strategy.
- Client route-aware components are narrow.
Securityβ
- Params/search params are validated.
- Redirect destinations are constrained.
- Resource authorization happens server-side.
- Link visibility is not treated as access control.
Accessibilityβ
- Navigation uses links/landmarks correctly.
- Active location is conveyed semantically.
- Back/Forward behavior is coherent.
- Scroll and focus are tested separately.
- Pending feedback is useful but not noisy.
Reliabilityβ
- Direct URL loads work.
- Reload works on query states.
- Back/Forward is tested.
- Production build passes.
- Rewrites do not create hydration mismatches.
Senior interview scenarioβ
Scenario: A product catalogue feels slow after the team migrated from a client SPA to App Router. Engineers suggest disabling Server Components and fetching everything with React Query.
A strong response would first decompose the navigation:
- Is the route dynamic?
- Are links being prefetched in production?
- Is there a
loading.tsxboundary? - How long is the server data path?
- Is the route payload or client JS large?
- Is query state causing repeated navigation?
- Are we measuring click-to-feedback or click-to-complete?
Then fix the identified bottleneck rather than replacing the architecture wholesale.
Senior interview scenario: return URLβ
Scenario: Login accepts ?returnTo= and calls:
router.push(searchParams.get('returnTo')!)
Problems:
- untrusted destination
- client-side decision may be later than necessary
- open redirect/script URL risk depending on handling
A stronger design:
- parse and validate internal return paths on the server
- reject scheme-relative/external destinations
- authenticate
- redirect to the validated path or safe default
Phase 3 milestone projectβ
Build an operations dashboard with:
/dashboard
/dashboard/jobs
/dashboard/jobs/[jobId]
/dashboard/jobs/[jobId]/logs
/dashboard/settings
and query state:
/dashboard/jobs?status=failed&owner=me&page=2
Requirements:
<Link>for normal navigation- active nav using route hooks
- Promise-based server
searchParams - validated filter/query parsing
- meaningful push/replace policy
loading.tsxon dynamic job detail- delayed
useLinkStatushint for a deliberately non-prefetched link - safe return-to flow
- Back/Forward and direct deep-link support
- scroll/focus review
- navigation analytics observer
- production build verification
Design documentβ
Write one page explaining:
- URL contract
- route ownership
- query-state schema
- prefetch policy
- loading-feedback policy
- history policy
- authorization boundaries
- accessibility behavior
- navigation performance metrics
- failure/debugging plan
If you can defend those decisions clearly, you understand App Router navigation beyond API memorization.