I have created a Gatsby app and configured gatsby-node.js to a create client only paths, which are all working fine in development while directly accessing the
For anyone who uses S3 (gatsby-plugin-s3) and CloudFront, I've resolve 302/404 by adding generateMatchPathRewrites: false in the gatsby-plugin-s3 config and creating a Lambd@Edge function for origin request with code below:
exports.handler = async (event) => {
const request = event.Records[0].cf.request;
if (/^\/app\//i.test(request.uri)) {
request.uri = '/app/index.html';
}
return request;
};
Though 302/404 went away, I still have the issue when doing a hard refresh. For example when I am at /app/page2 and hit refresh, the default component in /app will load then half a second later the component in /app/page2 will show up but in a weird way. Some css classes of /app is mixed in /app/page2. If anyone has any idea about this, please let me know.