Elliot Sutton

Page Transition (TanStack Router)

Navigation

About

A layout wrapper that animates transitions between pages of a TanStack Router app using the browser's View Transitions API, with multiple built-in transition effects and shared-element morphing.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Page Transition (TanStack Router) to your project and fits it to your theme.

Code

How Page Transition (TanStack Router) is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

"use client";

import { PageTransition } from "@/components/ui/page-transition-tanstack-router";
import {
  createRootRoute,
  createRoute,
  createRouter,
  createMemoryHistory,
  RouterProvider,
  Link,
  Outlet,
} from "@tanstack/react-router";

function RootLayout() {
  return (
    <div className="w-full max-w-md overflow-hidden rounded-xl border bg-background">
      <nav className="flex gap-1 border-b p-2">
        <Link
          to="/"
          className="rounded-md px-3 py-1.5 text-sm text-muted-foreground transition-colors hover:text-foreground [&.active]:bg-accent [&.active]:text-foreground"
        >
          Home
        </Link>
        <Link
          to="/about"
          className="rounded-md px-3 py-1.5 text-sm text-muted-foreground transition-colors hover:text-foreground [&.active]:bg-accent [&.active]:text-foreground"
        >
          About
        </Link>
      </nav>
      <PageTransition
        effect="slide"
        className="relative flex h-64 flex-col justify-end gap-1.5 bg-background p-6"
      >
        <Outlet />
      </PageTransition>
    </div>
  );
}

const rootRoute = createRootRoute({ component: RootLayout });

const indexRoute = createRoute({
  getParentRoute: () => rootRoute,
  path: "/",
  component: () => (
    <>
      <h2 className="text-2xl font-medium">Home</h2>
      <p className="text-sm text-muted-foreground">
        Animated page transitions for TanStack Router, built on view
        transitions.
      </p>
    </>
  ),
});

const aboutRoute = createRoute({
  getParentRoute: () => rootRoute,
  path: "/about",
  component: () => (
    <>
      <h2 className="text-2xl font-medium">About</h2>
      <p className="text-sm text-muted-foreground">
        Swap pages and the transition plays automatically.
      </p>
    </>
  ),
});

const routeTree = rootRoute.addChildren([indexRoute, aboutRoute]);

const router = createRouter({
  routeTree,
  history: createMemoryHistory({ initialEntries: ["/"] }),
  defaultViewTransition: true,
});

export default function PageTransitionTanstackRouterDemo() {
  return (
    <div className="flex w-full items-center justify-center p-8">
      <RouterProvider router={router} />
    </div>
  );
}

Dependencies

More by Elliot Sutton

View all
  • Notification List

    Notification List

    248
  • Glyph Background

    Glyph Background

    246
  • Topography Background

    Topography Background

    192
  • Scroll Progress

    Scroll Progress

    151
  • Cursor

    Cursor

    147
  • Pin List

    Pin List

    120
  • Avatar Group

    Avatar Group

    115
  • Bubble Background

    Bubble Background

    111

More in Navigation

View all
  • Footer with Big Wordmark

    Footer with Big Wordmark

    171
  • Liquid Glass Expandable Sidebar

    Liquid Glass Expandable Sidebar

    449
  • Meniscus — Liquid Bottom Navigation Bar

    Meniscus — Liquid Bottom Navigation Bar

    33
  • Sidebar

    Sidebar

    444
  • Stacked Circular Footer

    Stacked Circular Footer

    470
  • Tabs

    Tabs

    38
  • Sidebar

    Sidebar

    367
  • Footer Section

    Footer Section

    3

Explore more

Part of Animate UI — browse the full library on 21st.dev.