Handle url redirects in angular-cli application deployed to github pages

1.3k views Asked by At

When an angular-cli application is deployed to github pages using the built-in command, the resulting site handles urls which don't actually map to a file. For example, links like https://amellnik.github.io/clarity-demo/inputs;foo=foo work, which uses both routing and matrix notation.

However, when I deploy a similar angular-cli application to github pages on an enterprise github instance, navigating to anything but the root url does now work. The application works fine if you start at the route and navigate around, but you can't reload the page. How do I set up github enterprise to handle these cases like normal github?

I know that https://github.com/jekyll/jekyll-redirect-from can be used for some redirects, but it doesn't seem to be able to do what I need here -- rewrite any url that doesn't correspond to an actual file to index.html.

1

There are 1 answers

1
ARM On BEST ANSWER

I realized that angular-cli uses the fact that github allows custom 404 pages, and writes a copy of index.html to 404.html after it builds the site, before pushing to the gh-pages branch. This can be done manually when deploying by hand. Details here.