Stripe Checkout Redirects in Next.js 16
Unanswered
rob posted this in #help-forum
robOP
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 (
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
What I’ve tried:
1. Route Handler returning JSON
2. Server Action with redirect()
The problem: With Server Actions using
Questions:
1. What’s the 2025 recommended pattern for dynamic cancel URLs?
2. Should I stick with Route Handlers returning JSON to avoid history pollution?
3. Or is there a way to use Server Actions that won’t pollute browser history?
Thanks!
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 param2. 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:
1. What’s the 2025 recommended pattern for dynamic cancel URLs?
2. Should I stick with Route Handlers returning JSON to avoid history pollution?
3. Or is there a way to use Server Actions that won’t pollute browser history?
Thanks!
1 Reply
Pacific sand lance
redirect accepts 2nd argument which is either push or replace, if u use replace it won;t
pollute history