I have an Angular app which is store in a AWS S3 bucket and distributed by Cloudfront.
Now I want to distribute my app in multiple languages. I've already translated my angular app and for each language I have on build.
So my S3 bucket looks like this:
de
/index.html
/script.js
en
/index.html
/script.js
For each language I want to serve another app.
In Cloudfront I created two Origins which points to Origin Path /de
and /en
So my URL schema is like this:
<appname>.<mydomain>.com/:lang
But my problem is, I dont get the Error Pages to work with these specific language folders. I need these Error Response Handlers to deliver the angular app(s) when a 404 occurred (due to a reload)
Does anyone know how I can solve this? Or should i create one more subdomain for each language? So it looks like this:
<lang>.<appname>.<mydomain>.com
I've recently bumped into the same problem. My situation:
Solution:
ng build -prod -aot --base-href /en/ --i18nFile=src/locale/messages.en.xlf --i1nFormat=xlf --locale=en
const path = require('path')
exports.handler = (evt, ctx, cb) => {
const { request } = evt.Records[0].cf
if (!path.extname(request.uri)) {
if (request.uri.startsWith('/fr'))
request.uri = '/fr/index.html'
else
request.uri = '/en/index.html'
}
cb(null, request)
}
Building Angular with the base path parameter will establish the right subdirectory for your Angular app. The rewrite will make sure that resource files will not be rewritten, but all your routes will be redirected to index.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With