DEV Community

Cover image for Redirecting mobile users to App or Play Store in NextJS
Andreas Bergström
Andreas Bergström

Posted on Edited on Originally published at andreasbergstrom.dev

Redirecting mobile users to App or Play Store in NextJS

If you're promoting a mobile app for both iOS and Android and want a single URL or QR code that drops users into the correct store, you don't need a 3rd-party redirect service. A NextJS middleware that matches userAgent against iP(hone|ad|od) and Android regexes does it in ~15 lines, runs before any render, and keeps the contact point — and any SEO it earns — on your own domain.

The full post walks through the middleware.ts plus the placeholder app/get.tsx page that triggers it, with notes on the iOS-vs-Android UX quirk and why owning that redirect matters once QR codes are out in the wild and outlive your vendor relationships.


Originally published at andreasbergstrom.dev — read the full post there.

Top comments (1)

Collapse
 
27_cuongguti_88cfdf16c03 profile image
27 Cuong Guti

Thank you