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

    245
  • Glyph Background

    Glyph Background

    243
  • Topography Background

    Topography Background

    185
  • Scroll Progress

    Scroll Progress

    151
  • Cursor

    Cursor

    147
  • Pin List

    Pin List

    119
  • Avatar Group

    Avatar Group

    112
  • Bubble Background

    Bubble Background

    111

More in Navigation

View all
  • Footer with Big Wordmark

    Footer with Big Wordmark

    162
  • Liquid Glass Expandable Sidebar

    Liquid Glass Expandable Sidebar

    427
  • Meniscus — Liquid Bottom Navigation Bar

    Meniscus — Liquid Bottom Navigation Bar

    27
  • Sidebar

    Sidebar

    441
  • Tabs

    Tabs

    38
  • Footer Section

    Footer Section

    2
  • Sidebar

    Sidebar

    366
  • Pagination

    Pagination

    119

Explore more

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