# Multi-page routes & forms

> Design clean multi-page navigation, multi-step wizards, dual client-and-server form validation, and URL-backed state so users never lose progress.

- Canonical: https://exaspark.ai/docs/forms-and-navigation/

## Navigation architecture that scales past five screens

Prototypes often stack everything onto one scrolling page with tabs toggled in memory. That breaks down once your product adds public marketing pages, sign-in, member settings, billing, and an admin panel.

Production software treats **routes as contracts**. Every primary screen owns a clear URL, enforces role rules on the server, respects browser Back and Forward history, and handles missing pages or signed-out deep links cleanly without blank screens.

In ExaSpark, declaring routes and validation rules plainly lets the Agent wire routing, server checks, and **Cloud** persistence together.

## Choosing the right navigation and flow pattern

Pick the navigation shell that fits how people use your product rather than cramming every screen into one crowded top bar.

| Product surface | Recommended navigation | Clean URL structure | Mobile adaptation |
| --- | --- | --- | --- |
| **Public site or storefront** | Minimal top header (4–5 links) + footer | `/`, `/pricing`, `/classes`, `/classes/:id` | Compact header with slide-over menu drawer |
| **Daily member workspace (App)** | Left sidebar on desktop; bottom tabs on mobile | `/dashboard`, `/bookings`, `/messages`, `/account` | 4–5 item bottom tab bar with safe-area padding |
| **Onboarding or checkout wizard** | Focused distraction-free shell with step count | `/book/:id?step=2` or `/onboarding?step=1` | Sticky step progress bar + Back / Continue footer |
| **Detail page with sub-views** | Breadcrumb back link + inner horizontal tabs | `/projects/:id/tasks`, `/projects/:id/files` | Scrollable tab strip + crisp back chevron |
| **Admin back-office** | Role-gated `/admin` layout distinct from public UI | `/admin/overview`, `/admin/orders`, `/admin/members` | Collapsible drawer prioritizing search and filters |

> **Note:** Keep top-level navigation to five items or fewer. Group secondary pages under one **Account** or **Settings** route with inner tabs instead of wrapping the navbar onto two lines.

## Designing forms and multi-step wizards users finish

Forms are where bookings, sign-ups, and payments either convert cleanly or silently lose customers.

### Single-page forms vs multi-step wizards

Keep quick actions — sign-in, contact inquiries, or profile updates (1–5 fields) — on one vertical screen with crisp labels.

Split longer workflows — client intake, custom quotes, or multi-session booking checkout (8+ fields) — into a **3 to 4 step wizard**:

- **Group by mental task.** Step 1 picks service and time; Step 2 collects contact details; Step 3 reviews totals and completes Stripe checkout.
- **Show clear progress.** Display `"Step 2 of 3 — Contact details"` and let users step back without losing entered values.
- **Keep one clear primary button.** Place `Back` as a quiet link and `Continue` or `Confirm & Pay` as the unmistakable primary CTA.

### Dual client and server validation

Never rely solely on browser validation, and never make users wait for a network trip to catch a missing `@` in their email.

- **Client validation for immediate guidance.** Validate required inputs, email syntax, and ranges inline on blur or submit. Place concise red messages directly under the offending input rather than in a vague top banner.
- **Server validation for data integrity.** Re-validate every payload server-side before writing to **Cloud** — checking capacity limits, role ownership, duplicate bookings, and pricing IDs so stale tabs or tampered requests never corrupt live records.

### Preserve progress, stop double submits, and confirm cleanly

Losing typed inputs on a validation error — or creating duplicate bookings when tapping **Pay** twice on mobile — breaks trust immediately.

- **Keep entered inputs on error.** Retain every valid field when validation fails and shift focus smoothly to the first invalid input.
- **Lock buttons while pending.** Switch submit into a disabled loading state (`"Saving..."`) backed by server duplicate protection.
- **Apply optimistic UI carefully.** Use instant updates for lightweight toggles (bookmarks, task checkboxes) with automatic rollback on failure; always wait for server confirmation on Stripe payments.

## URL state: filters, tabs, search, and pagination

Storing search queries, category filters, sort order, or page numbers strictly in local component state feels fragile: refreshing wipes the view, hitting Back from a detail page resets filters, and teammates cannot share filtered links.

Mirroring shareable view state in URL query parameters solves all three problems. Here is a URL map for a booking and membership app:

```text
Public Discovery Routes:
  /                                   → Homepage hero & overview
  /classes?day=thu&level=beginner     → Filterable schedule (URL state)
  /classes/:slug                      → Class details & live seat count
  /pricing                            → Memberships & class packs

Member Routes (signed-out visits redirect to /login?next=<path>):
  /book/:classId?step=2               → Multi-step booking & Stripe deposit
  /account/bookings?tab=upcoming      → Member history with URL-backed tabs
  /account/billing                    → Active plan + Manage Billing link

Admin Routes (server enforces Admin role):
  /admin/orders?status=pending&page=2 → Shareable paginated orders table
  /admin/classes/new                  → Create class form with unsaved guard
  /404                                → Branded Not Found page with Home link
```

Notice `/login?next=<path>`: when a signed-out member clicks an email link to `/account/bookings`, signing in returns them straight to that screen instead of stranding them on `/`.

## Building a rock-solid multi-step flow in ExaSpark

Follow this five-step workflow to ship durable multi-page navigation and forms.

1. **Map routes and role gates upfront** — Name public, member, and admin paths explicitly in your prompt or `PROJECT_RULES.md` so redirects and server checks match from turn one.
2. **Bind every input to Cloud columns** — Specify required fields, types, and formats so frontend inputs, API checks, and relational **Cloud** tables stay aligned.
3. **Add wizard draft saving and double-submit locks** — Persist multi-step drafts across step navigation and reloads (clearing on success) and disable buttons while requests run.
4. **Move filters, tabs, and pagination into URL params** — Sync search and list filters to the query string so browser Back and shared links preserve exact views.
5. **Stress-test edge cases in Preview** — Submit blank forms, double-click submit buttons, open `/account` while signed out, and press browser Back mid-wizard before clicking **Publish**.

Build a resilient multi-step intake and booking wizard cleanly:

> **Example prompt (App):** Build a 3-step booking wizard at /book/:serviceId (Step 1: pick date and time slot with live Cloud capacity check; Step 2: client name, email, phone, and optional notes; Step 3: review summary and pay Stripe deposit). Validate inline per step and enforce identical validation server-side before saving. Preserve draft inputs when stepping back or refreshing, disable submit buttons while pending to stop duplicate Cloud rows, and clear the draft on confirmation.

Upgrade an existing storefront or admin table with URL-backed filters, `?next=` login redirects, and branded 404 handling:

> **Example prompt (Web):** Upgrade routing and list state on our catalog and /admin/orders views: store search query, status filter, sort order, and page number in URL query parameters so reloads and browser Back preserve the exact view. Add ?next= return redirects when signed-out users open protected /account URLs, and add a branded 404 page linking back to Home and Schedule. Leave Cloud schemas and Stripe handlers unchanged.

## Common routing and form failures

Eliminate these six recurring multi-page bugs during **Preview** testing.

| Symptom | Root cause | Exact fix |
| --- | --- | --- |
| **Pressing Back on Step 2 wipes Step 1 inputs** | Values lived inside unmounted child step state | Lift wizard state to a parent store or draft storage cleared only on final success |
| **Double-tapping Submit creates duplicate Cloud rows** | Submit stayed enabled during the network request | Disable submit with a loading label immediately and add server duplicate protection |
| **Form passes browser checks yet fails silently** | API rejected the payload without displaying server errors | Return structured field-level errors from the API and render inline messages |
| **Refreshing a filtered list resets to page 1** | Filters lived in memory instead of URL query params | Store search, filter, sort, and page values in URL params (`?status=paid&page=2`) |
| **Protected route hits a signed-out redirect loop** | Auth guard redirected before session loading finished | Wait for auth session resolution, then redirect to `/login?next=<path>` |
| **Validation error hides off-screen on mobile** | Failed submission did not move viewport or focus | Scroll smoothly to and focus the first invalid field automatically |

## Next steps

- [Search, filters & pagination](https://exaspark.ai/docs/search-filtering-pagination/) — Scale large Cloud datasets with server pagination and crisp filter URLs.
- [User profiles & onboarding](https://exaspark.ai/docs/user-profiles-onboarding/) — Guide newly signed-up members smoothly to their first core action.
- [Authentication & roles](https://exaspark.ai/docs/authentication-and-roles/) — Enforce public, member, and admin route boundaries on the server.
- [Accessibility & UI polish](https://exaspark.ai/docs/accessibility-and-motion/) — Combine clean forms with keyboard focus, ARIA labels, and complete states.

## From the blog

- [How to build a booking app](https://exaspark.ai/blog/how-to-build-a-booking-app/) — Practical blueprint for multi-step scheduling, validation, and deposits.
- [How to build a SaaS product](https://exaspark.ai/blog/how-to-build-a-saas-product/) — Structure dashboards, onboarding flows, and recurring billing cleanly.
- [Frontend vs backend explained](https://exaspark.ai/blog/frontend-vs-backend/) — Why client validation and server validation solve distinct problems.
