Terminal
1npm install next-transition-router gsap
Pages rotate vertically like faces of a 3D cube (rotateX). Page flips up and away while new page rotates in from below. Natural scroll-like direction.
npm install next-transition-router gsapperspective: 1200px on containerrotateX: ±90 for vertical cube rotationtransformOrigin: center top/bottom for pivot1npm install next-transition-router gsap
1'use client'23import { useRef } from 'react'4import { TransitionRouter } from 'next-transition-router'5import gsap from 'gsap'67export default function CubeProvider({ children }: { children: React.ReactNode }) {8 const wrapperRef = useRef<HTMLDivElement>(null)910 return (11 <div style={{12 perspective: '1200px',13 perspectiveOrigin: 'center center',14 overflow: 'hidden',15 minHeight: '100vh',16 }}>17 <TransitionRouter18 auto19 leave={(next) => {20 const tl = gsap.timeline({ onComplete: next })21 const wrapper = wrapperRef.current2223 // Vertical cube rotation - rotate UP (rotateX)24 tl.to(wrapper, {25 rotateX: 90,26 y: -100,27 opacity: 0,28 duration: 0.6,29 ease: 'power3.inOut',30 transformOrigin: 'center top',31 })32 }}33 enter={(next) => {34 const tl = gsap.timeline({ onComplete: next })35 const wrapper = wrapperRef.current3637 // Coming from below (vertical cube)38 gsap.set(wrapper, {39 rotateX: -90,40 y: 100,41 opacity: 0,42 transformOrigin: 'center bottom',43 })4445 // Rotate into view vertically46 tl.to(wrapper, {47 rotateX: 0,48 y: 0,49 opacity: 1,50 duration: 0.6,51 ease: 'power3.inOut',52 })53 }}54 >55 <div ref={wrapperRef} style={{ transformStyle: 'preserve-3d' }}>56 {children}57 </div>58 </TransitionRouter>59 </div>60 )61}