Skip to the solution
MediumFrontend8 min read

How do View Transitions work with next/link transitionTypes in Next.js 16.2?

808 views

The problem

Question presented to candidate: "Designers want the photo detail page to slide in from the right when you open it and slide back when you return to the gallery, and no animation for other navigations. Next.js 16.2 added transitionTypes on <Link>. How does that work end to end, and what do you need in the app today?"

What a strong answer should cover:

  • The browser View Transitions API snapshots the old and new UI and animates between them; React's <ViewTransition> component drives it declaratively.
  • App Router navigations are React Transitions, so <ViewTransition> animates on navigation automatically.
  • transitionTypes={["nav-forward"]} on <Link> (added in 16.2) passes those strings to React.addTransitionType inside the navigation; <ViewTransition enter={{ "nav-forward": "...", default: "none" }}> maps types to CSS classes.
  • The CSS lives in ::view-transition-old(.class) / ::view-transition-new(.class) rules; respect prefers-reduced-motion.
  • Version detail: <ViewTransition> is stable in React 19.3 and imported from react; on 16.4.2 the old experimental.viewTransition flag is rejected, and browsers without support simply do not animate.

Clarifying questions expected:

  • "Which navigations count as forward and back?" β€” the type is not automatic; you assign it per link.
  • "What about the browser back button?" β€” it is not a <Link> click, so it carries no type.

Code / implementation expected: Yes β€” two pages, the links with types, a shared <ViewTransition> wrapper and the CSS.

  • nextjs
  • navigation
  • view-transitions
  • next-16

Try it yourself

Sketch your approach before you read the solution. That is what the interview tests.

Stuck? Get a hint.

A short nudge toward the approach. It will not give the answer away.

Solution

The solution is hidden so you can try first

8 min read Β· 8 sections

Read the code

Page wrapper mapping types to animations
import { ViewTransition } from "react";

export function Slide({ children }: { children: React.ReactNode }) {
  return (
    <ViewTransition
      enter={{ "nav-forward": "nav-forward", "nav-back": "nav-back", default: "none" }}
      exit={{ "nav-forward": "nav-forward", "nav-back": "nav-back", default: "none" }}
      default="none"
    >
      {children}
    </ViewTransition>
  );
}
Links with transition types
// app/vt/page.tsx
import Link from "next/link";
import { Slide } from "./slide";

export default function Gallery() {
  return (
    <Slide>
      <main>
        <h1>Gallery</h1>
        <Link href="/vt/detail" transitionTypes={["nav-forward"]}>Open photo</Link>
      </main>
    </Slide>
  );
}

// app/vt/detail/page.tsx
// <Link href="/vt" transitionTypes={["nav-back"]}>Back to gallery</Link>

Discussion

Other approaches, follow-ups and how it went in real interviews.

Sign in to join the discussion.

No comments yet. Share how you would answer it.

Question 49 of 129 in Next.js

Keep your momentum going.

Mark this question solved to track your progress, then take the next one while it is fresh.

All Next.js questions
Up nextMedium

How does next/image optimize images in Next.js?

Continue