Move redirect logic to the entry file#362
Conversation
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Maybe things have changed, but the last time I talked with @blittle the idea was to remove all the redirect stuff out of each route file and only put it into server.ts?
[edit] whoops I think I misread something, that's what it appears you're doing. Excellent. 👍
| return false; | ||
| } | ||
|
|
||
| type RedirectQueryType = { |
There was a problem hiding this comment.
In general we should probably never make our own Storefront API types - you can get this type by doing:
import type {UrlRedirectConnection} from '@shopify/hydrogen-react/storefront-api-types';There was a problem hiding this comment.
I did that at the beginning and then reverted it to the original hardcoded version because I thought @shopify/hydrogen didn't depend on @shopify/hydrogen-react. Turns out it has it as a peer dependency so I will change it again 😅
blittle
left a comment
There was a problem hiding this comment.
Looks good after that query issue is fixed. Thx Fran!
Co-authored-by: Bret Little <bret.little@shopify.com>
Instead of calling
notFoundMaybeRedirect, this changes it to throw 404 responses in the routes and then redirect conditionally inserver.ts.Some things to consider:
storefrontRedirect. Open to other names 🙏Questions:
🎩 :
/collections/hydrogenshould redirect to/collections/backcountry./collections/xyzshould show a 404 page./collections/xyz?return_to=/aboutand/collections/xyz?redirect=/aboutshould redirect accordingly./collections/xyz?return_to=https%3A%2F%2Fgoogle.comshould show a 404 page and warn in the terminal about cross-domain redirects.