All articles Fundamentals

Session Replay for Single-Page Apps: Routes Done Right

Engineer watching a branching blue light path across a dark glass floor, illustrating navigation routes in a single-page app

Your product never reloads. A visitor lands on pricing, signs up, opens the dashboard, edits a record, hits a validation error and leaves — all inside one document. A recorder built for classic multi-page sites watches that journey and logs a single page view. You open the session and the timeline is a flat line with one URL at the top.

That is why session replay for a single-page app is a routing problem before it is a recording problem. The recorder has to read the History API, treat client-side route changes as navigations, keep one recording per visit instead of one per document load, and stay off the routes where it does not belong.

Here is how replay handles route changes in React, Vue and Next.js, how to keep a multi-page visit as one recording, and how to load the recorder only on the pages that need it. Prynt Replay is the working example.

A route change is a navigation, not a session

Classic recorders start on page load and stop on unload. Inside an SPA those events fire once, at the very beginning and the very end, so everything in between stays invisible unless the recorder listens to something else.

What it should listen to:

  • pushState and replaceState, covering programmatic navigation and the redirect after login.
  • popstate, the back and forward buttons, which produce most “the recording ends here” reports.
  • hashchange, for hash routers and in-app anchors.

Each one becomes a synthetic page view with URL, timestamp and trigger. A page view is a segment inside the session, never a new session. Boundaries stay where they belong — idle timeout or a deliberate end — so a visitor who moves through six screens is six segments in one recording, not six orphaned recordings.

Normalize before you count

Query strings flood you if you let them: /app/orders?tab=open and /app/orders?tab=closed are one route with different state. Group page views by route pattern so heatmaps and funnels do not fragment, and debounce search-as-you-type or you record a page view per keystroke.

One visit, one recording: what stitching changes

Once route changes are segments, the timeline reads like the visitor’s actual path: landing, pricing, signup, onboarding, error. Three things improve immediately.

Hands arranging translucent blue-lit glass panels on a black desk, representing stitched session segments

Heatmaps attach to a route instead of a document. Click maps on /pricing stop being polluted by clicks on /dashboard, and scroll depth means something again.

Errors keep context. A JavaScript error carries the route where it fired, so “TypeError on /app/reports after the second navigation” becomes a bug report instead of a mystery.

Funnels survive the app shell. Because the session spans routes, you can follow a checkout that runs across four client-side navigations — exactly the flow that matters.

One caveat to plan for: with no document reload, Web Vitals must be attributed to the route you defined, not to the document. Define navigation explicitly and route-level performance stays readable; skip it and every number collapses into the first load.

Load the recorder only where it is needed

The recorder is a bundle. In an SPA it competes with the code your users are waiting for, so treat it as a deferred feature, not part of the shell.

Load it after the app is interactive through a dynamic import rather than a static one, so it never blocks first paint. Then decide where it runs:

  • Record authenticated app routes, checkout and onboarding, where a broken flow costs money.
  • Skip legal pages, password reset and any URL carrying a one-time token.
  • Skip public marketing pages if you measure those elsewhere, or you pay for sessions nobody debugs.
  • Gate on consent where your policy requires it.

In React, initialize once from a top-level effect and subscribe to the router’s location changes. In Vue, hook router.afterEach. In Next.js App Router, mount the loader in a client component inside the layout, which stays mounted across navigations, and guard against double initialization — a missing guard is the usual cause of duplicated page views after a route change.

Masking has to survive the navigation too

Client-side rendering creates form fields after load and after every transition, so masking applied once at initialization leaks the fields rendered later. Prynt Replay masks every form field in the browser and again on the server, with no unmask option, so fields that appear after a route change fall under the same rule; the details are on our security page.

Put the sessions where your team already works

Support and success teams rarely open a separate replay tool. Prynt Replay lets you call identify(userId, { accountId }), list an account’s sessions with the secret key, and open them in an embedded player inside your own admin — per company or per user, under the same masking rules. Setup lives in the docs, and the platform page shows how Replay shares one browser agent and one bill with the rest of the suite.

Dark hardware faceplate with only some ports lit blue, illustrating loading a recorder only on some routes

Bot sessions do not count against your quota, which matters for SPAs that get crawled and probed more than they get used.

FAQ

Does session replay work with the Next.js App Router?

Yes, if the loader lives in a client component that survives navigation. App Router keeps layouts mounted, so initialize once and let the router listener record later route changes instead of re-initializing on every render.

Will one SPA visit show up as one recording or several?

One, when route changes are recorded as segments and only an idle timeout or an explicit end closes the session. Several recordings for a single visit usually mean the recorder treats popstate or replaceState as a page unload.

Can I record only part of my app?

Yes. Gate the dynamic import on the route: load the recorder on authenticated routes and checkout, skip legal, reset and marketing pages.

Start with one route

Pick the authenticated route where users complain most, turn Replay on there, and read the first twenty sessions before widening the scope. Route-level heatmaps and JS errors usually give you something to fix in the same week, and the free plan covers 1,000 sessions a month with 14-day retention — enough for a first honest pass.

Translucent blue-lit cube on a black table with two colleagues talking, representing sessions embedded in an admin

Start recording your SPA with Prynt Replay

Try it free

Prynt is device intelligence with a free plan: 5,000 identifications a month, visitor IDs with confidence and bot detection — no credit card. Upgrade to Pro for VPN, proxy, tampering and behavioral signals.

Keep reading