Search code examples
javascriptcssangulargitgithub-pages

Deploy Angular Application in GitHub Pages


I have a GitHub pages website that uses a custom domain.

The domain serves a webapp made in Angular but when I access my domain the .js and .css files are not loading and on DevTools/Network I see a 404 Not Found per each .js or .css file I have on the branch assigned to the GitHub pages domain.

Js and CSS file on my gh-pages branch

Error shown on DevTools Network tab


Solution

  • It's a common problem in Angular. When you generate the bundles you need to use:

    ng build --prod --base-href ./ 
    

    to set base-href to the root folder containing the bundles. Or if you already deployed the project just edit index.html and change the base tag to

     <base href="./">
    

    More information in the docs.