Best way to redirect to external URL
Answered
Jersey Wooly posted this in #help-forum
Jersey WoolyOP
I have 2 Next apps in a monorepo.
- App A is for marketing site, CMS, etc. on the main domain. Let's call it domain .com
- App B is the SaaS app on a subdomian app.domain .com
I'm thinking of the best option to redirect the user. Filling a form field on domain .com and redirecting them to app.domain .com/search/[inputFieldQuery]
A simple <a> tag would not be so elegant IMO. Also, I want the for to be submittable, so for example it works by just pressing return.
Next.js redirect() function and next config redirects are not working for external URLs. window.open() is usually blocked on modern browsers.
What would be the best way to achieve this functionality?
- App A is for marketing site, CMS, etc. on the main domain. Let's call it domain .com
- App B is the SaaS app on a subdomian app.domain .com
I'm thinking of the best option to redirect the user. Filling a form field on domain .com and redirecting them to app.domain .com/search/[inputFieldQuery]
A simple <a> tag would not be so elegant IMO. Also, I want the for to be submittable, so for example it works by just pressing return.
Next.js redirect() function and next config redirects are not working for external URLs. window.open() is usually blocked on modern browsers.
What would be the best way to achieve this functionality?
Answered by Jersey Wooly
I ended up merging the 2 apps together instead. The issues I had the resolve by merging the 2 apps is easier than a redirect. lol. It looks like currently, there's no way to redirect users to a different URL on the web because there's a high chance that it'll be blocked by the browser
5 Replies
Asian black bear
You could make a path with
route.ts that returns a 307 or 308 redirect.To a single path in your SaaS app like
/ or maybe have it take a path relative to app.domain.com/saasApp/[[...path]]/route.ts seems like a good place to start for the latter strategyOrinoco Crocodile
Take a look at https://github.com/vercel/platforms/tree/main. That repo covers your use case.
Jersey WoolyOP
I ended up merging the 2 apps together instead. The issues I had the resolve by merging the 2 apps is easier than a redirect. lol. It looks like currently, there's no way to redirect users to a different URL on the web because there's a high chance that it'll be blocked by the browser
Answer