SSGOI

Persistent layouts

Keep a bottom nav or header still while the pages under it change.

The quick start uses the path as both the boundary key and the transition id, so every navigation replaces the whole page. Keep that version until part of the routed UI has to survive a navigation — then split the page into the few lifetimes the product actually needs.

Keep a bottom nav still while tabs change

Say /, /collections and /create are tab pages sharing one bottom nav, and /photo/[id] is a detail page without it. Tab → tab should move only the content. Tab → detail should send the whole shell away, nav included.

With one boundary keyed by the path at the root, React remounts everything on every navigation, so the nav animates on tab → tab too.

Two mobile navigation cases: tab-to-tab moves only inner content while the bottom navigation stays fixed; tab-to-detail moves the entire shell including the bottom navigation
Tab → tab: the inner content changes and BottomNav stays mounted. Tab → detail: the outer shell leaves and takes BottomNav with it.

Change the key to animate, keep the attribute truthful

A boundary carries two values, and only one of them starts anything. The key decides when the DOM node is replaced, and SSGOI reacts to the framework destroying and rebuilding the routed node. data-ssgoi-transition is the route id used to pair the leaving page with the arriving one and to match your config rules. SsgoiLayoutBoundary sets both for you: the id is always the route path, and the key comes from config.layouts.

Changing only the attribute on a still-mounted node produces no transition: the engine registers each element once and never re-reads it as a new arrival. Change the key when you want motion; keep the attribute equal to the route so rules keep matching.

Declare the layout tree in config

config.layouts describes which routes share a layout. Each scope has paths, an optional except, and optional child layouts. Siblings are tried in order and the first match wins; children describe the next depth inside that scope. Patterns use the route-rule syntax, and a * or :id segment makes each captured value its own instance, so /projects/1 and /projects/2 get separate shells while a ** tail does not (which is why the shop section uses /shop/**, not /shop/*). This is the layout of the Next.js template:

// Bottom-nav tabs, including every shop category.
const TOP_LEVEL = ["/posts", "/shop/**", "/pinterest", "/profile"];

const config = {
  layouts: [
    // depth 0: one shell for the tabs; depth 1: the shop section inside it
    { paths: TOP_LEVEL, layouts: [{ paths: "/shop/**" }] },
    // depth 0: one shell for every detail page
    { paths: "/**", except: TOP_LEVEL },
  ],
  transitions: [
    { from: TOP_LEVEL, to: TOP_LEVEL, transition: fade() },  // tab ↔ tab
    /* drill / zoom for details, slide for categories */
  ],
};

Then place prop-less boundaries in the layouts that own each lifetime. Depth is automatic: a boundary with no boundary above it is depth 0, and each boundary inside another is one deeper. A boundary at depth N keys by the scope instance that matches at depth N, and by the route path when nothing matches there.

app/
├─ layout.tsx                      <Ssgoi> + boundary               depth 0
├─ (top-level)/layout.tsx          boundary + <BottomNav /> outside depth 1
│  ├─ posts/page.tsx               /posts
│  ├─ pinterest/page.tsx           /pinterest
│  ├─ profile/page.tsx             /profile
│  └─ shop/layout.tsx              header + category tabs + boundary depth 2
│     ├─ page.tsx                  /shop (All)
│     └─ electronics/, ...         /shop/electronics, /shop/fashion, ...
└─ (detail)/layout.tsx             boundary                         depth 1
   └─ posts/[id], pinterest/[id], profile/[id]

tab → tab           : depth 0 key stays · depth 1 key changes · nav stays
category → category : depth 0 and 1 keys stay · depth 2 slides · tabs stay
tab → detail        : depth 0 key changes · the whole tab shell leaves, nav included
detail → detail     : depth 0 key stays · depth 1 key changes

When a parent and a child boundary leave in the same DOM mutation, the outer one owns the transition and the child is cleaned up silently. Arrivals resolve the same way — inside one mount batch only the outermost boundary plays an entrance. The child therefore owns the motion only while its parent stays mounted, and that is what lets one nesting serve both tab and detail navigation. Without layouts, every boundary keys by the path, which is the quick-start behavior.

Intercepted modals keep the background

During a soft intercepted modal the URL becomes /p/42 while the children slot still renders the background. The Next.js framework returns a renderedPath built from the selected layout segments, so boundaries follow what is actually rendered and the background stays mounted. Render the {modal} slot outside the boundaries; nothing modal-specific is configured.

Your app still owns intercepting route files, parallel slot fallbacks, and any redirects or rewrites in middleware.ts (Next 13–15) or proxy.ts (Next 16+). Review those rules for soft navigation and direct entry, and test open, close/back, and reload with that configuration enabled. This is separate from SSGOI’s animation middleware.

A production tree

Comwit runs this on a Next.js App Router tree with tabs, full-page details, a persistent project workspace and intercepted modals. Route groups and parallel slots decide which layouts stay mounted; one provider observes them all.

app/
└─ (app)/
   ├─ layout.tsx                         # one provider + depth-0 boundary
   ├─ (top-level)/
   │  ├─ layout.tsx                      # depth-1 boundary + BottomNav + @modal
   │  ├─ projects/page.tsx               # /projects
   │  ├─ showcase/page.tsx               # /showcase
   │  ├─ comwit-log/page.tsx             # /comwit-log
   │  ├─ profile/page.tsx                # /profile
   │  └─ @modal/
   │     ├─ default.tsx                  # no modal
   │     └─ (.)p/[id]/page.tsx           # soft /p/42 over the current tab
   └─ (detail)/
      ├─ p/[id]/page.tsx                 # direct /p/42, full page
      └─ projects/[id]/
         ├─ layout.tsx                   # persistent project header + tabs
         ├─ page.tsx                     # /projects/acme
         ├─ members/page.tsx
         ├─ board/
         │  ├─ layout.tsx
         │  └─ @taskSidebar/...          # parallel task panel
         └─ docs/
            ├─ layout.tsx
            ├─ [docId]/page.tsx
            └─ @docSidebar/...          # parallel document panel
layouts: [
  { paths: ["/projects", "/showcase", "/comwit-log", "/profile"] },
  { paths: "/projects/:id/**" },   // one instance per project
]

Large tree, small ownership: one provider, one depth-0 boundary, one depth-1 boundary for top-level content. Everything under /projects/acme shares one depth-0 instance, so the project header and its loaded state survive while the id keeps following the full route. The immediate project child has no boundary on purpose — overview → docs is a child swap, not a page transition.

Comwit route ownership: one SSGOI provider contains an outer app-shell boundary, an inner main-content boundary for top-level tabs, persistent bottom navigation, project shells keyed by project base path, and intercepted modals as parallel siblings
The four navigation cases differ only in which boundary key changes.
CaseBrowser URLRendered pathDepth-0 keyResult
Top-level tab/projects/projectstop-level scopeShell persists; the depth-1 boundary owns the motion.
Generic detail/p/42/p/42/p/42Key changes; the tab shell and nav leave together.
Same-project child/projects/acme/docs/projects/acme/docsproject scope, acmeProject shell persists; its child swaps immediately.
Soft intercepted modal/p/42/projectstop-level scopeBackground stays mounted; the modal renders above it.

When it goes wrong

Every symptom below is the wrong lifetime, not a wrong transition.

  • BottomNav moves on tab → tab. It is inside the depth-1 boundary, or the tabs are missing from the top-level scope in layouts.
  • BottomNav stays on a detail page. It sits outside the depth-0 boundary. Move it inside the one that changes when you leave the tab group.
  • Opening a modal animates the background. The framework returns only the URL pathname. Return renderedPath from the selected segments, and render the modal slot outside the boundaries.
  • Project tabs replay the full page. A boundary wraps the project child, or the project scope uses /projects/** where it needs /projects/:id/**.
  • The wrong scope wins. Siblings are first-match: put narrower scopes before broad ones, or exclude them with except.

Rules that generalize

  • One provider per navigation surface. Nested lifetimes need nested boundaries, not nested providers.
  • Mirror your layout files in layouts: one scope per layout that should stay mounted, nested the same way.
  • The id is always the route path, so route rules keep matching while keys are shared.

Copy-ready layouts and a checklist live in /llms/complex-routing.txt. For a working example, see the Next.js template.

Read next