Skip to content

Files

Latest commit

94e70d3 · Feb 5, 2025

History

History

example

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
May 10, 2023
Feb 5, 2025
Oct 16, 2024
Jan 19, 2023
Oct 16, 2024
Sep 26, 2024
Mar 5, 2024
Sep 26, 2024
Jan 19, 2023
Jan 19, 2023
Jun 24, 2024

README.md

Next.js with Unleash

Deploy with Vercel Edit in CodeSandbox

To run this code locally:

git clone https://github.com/Unleash/unleash-client-nextjs.git
cd unleash-client-nextjs/example
pnpm install
pnpm dev

Open http://localhost:3000 with your browser to see the result.

Flag in use is example-flag. https://app.unleash-hosted.com/demo/projects/codesandbox/features/example-flag

Available examples

App Router

Pages Router

API

Middleware

Example of A/B testing with Next.js Middleware. Redirect users to a different (pre-rendered) page based on a feature flag.

  • ./src/pages/api/proxy-definitions.ts - act as cache for feature flag definitions. This lets this SDK act as a substitute for Unleash Edge or the Unleash proxy that you can deploy on Next.js Edge.
  • ./src/middleware.ts - handle flag evaluation and transparently redirect to one of the pages in ./src/pages/ab directory
  • ./src/pages/ab/a & ./src/pages/ab/b - target pages. Both will be served at the URL /ab, but which one you see is decided by the feature flag in ./src/middleware.ts.