Stripe Checkout Redirects in Next.js 15
Hey everyone! I'm integrating Stripe Checkout with Next.js 16 and need help with the best approach for handling redirects.
Use case:
Users can click "Upgrade" from multiple pages (/settings, /pricing)
After clicking, they go to Stripe Checkout
When they click the back arrow on Stripe, I want them to return to the page they came from
The Stripe cancel_url needs to be dynamic based on the originating page
What I’ve tried:
1. Route Handler returning JSON
// API route returns: { url: stripeCheckoutUrl }
// Client fetches, then navigates: window.location.href = url
// Pass returnUrl via query param
2. Server Action with redirect()
'use server'
export async function createCheckout() {
const session = await stripe.checkout.sessions.create({...})
redirect(session.url!)
}
The problem: With Server Actions using redirect(), the redirect enters browser history. When users click back from Stripe, they hit the server action again and get redirected elsewhere.
Questions:
- What’s the 2025 recommended pattern for dynamic cancel URLs?
- Should I stick with Route Handlers returning JSON to avoid history pollution?
- Or is there a way to use Server Actions that won’t pollute browser history?
Thanks!