Goal
Serve all files excluding index.html on a CDN (CloudFront). Thus the app is served on a subdomain that's different than the assets.
Problem
I used ng build --prod --aot --base-href https://mycdn.x.com
to build my app, and then sent all the files over to my CDN. An nginx server is serving index.html
What happened is that on app load, I got the following error:
Uncaught (in promise): SecurityError: Failed to execute 'replaceState' on 'History':
A history state object with URL 'https://mycdn.x.com/' cannot be created in a document with origin
'https://myapp.x.com' and URL 'https://myapp.x.com/page1/page2'.
Notes
How can I serve all assets from a CDN while keeping the app sane?
Found the solution, should've used --deploy-url
not --base-href
.
ng build --prod --aot --deploy-url https://mycdn.x.com