Angular app on Kubernetes Ingress when using non-root path

I have an Angular app which works perfectly in the development environment.

When I try to deploy it to a Kubernetes cluster and create an ingress route for it, things don’t work as expected.

Specifically, I’m using this ingress definition

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: angular-website
  annotations:
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
  - http:
      paths:
      - backend:
          serviceName: angular-website
          servicePort: 80
        path: /website(/($|.*))?

When I try to go to that ingress route, I see a blank page and it the network tab (in Chrome), I see these errors

enter image description here

I realize that this is happening because I’m trying to route on a non-root path (i.e. something that isn’t /), and Angular isn’t "aware" of that and assumes that the app runs from the root path when it tries to load all the JS bundles.

I realize that I can fix this by editing a section in the main index.html in my application from

<base href="/">

to

<base href="/website">

But I rather not do that since it would require me to know the path ahead of time, during build.

Is there a way around it? Is there a way to make Angular dynamically be aware of the root path without having to recompile the app to set that?

Source: Angular Questions