4

I have my angular2 application in production. And whenever i deploy a new version of my application for some time (due to caching of index.html) the old index.html is served and since the old js files gets replaced with new js files I get 404 errors for my old js files. Though this problem goes away with time I wanted a angular-cli build solution such that I can keep the old files on my server and remove it after next 2 subsequent releases.

I tried doing this in my jenkins, ng build -prod -aot --base-href="/myapp/10.5.0/"

But the problem is, whenever I deploy this app the following folder path gets attached to the address-bar URL http://localhost/myapp/10.5.0/

I don't want to append the base-href to be attached to the URL.

In-case I achieve this, Than I can have many version folders and the old (cached) index.html will serve from the old folder and would still work without giving 404 errors.

Any help will be much appreciated.

Gan
  • 937
  • 8
  • 22

1 Answers1

0

I was able to accomplish a very similar goal by executing the following after my page finished loading:

<script type="text/javascript">
window.history.pushState('any-value', 'My Website', '/url/without/base/href');
</script>

So in your case, that would probably be something like:

<script type="text/javascript">
window.history.pushState('any-value', 'My Website', '/');
</script>

This changes the URL in the address bar without redirecting the user anywhere. My inspiration came from this Stack Overflow response: Modify the URL without reloading the page

John Langford
  • 1,272
  • 2
  • 12
  • 15