3

HTML5 PushState means refresh URL or enter direct URL in browser works perfectly fine when I run my angular app using 'npm start' command from VS 2015 command prompt. However when I deploy same application on IIS and change <base href="/"/> to <base href="/MyVirtualApplication/" /> then HTML5's PushState or History API doesn't work properly and raising 404 error.

Please do suggest.

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Avi Kenjale
  • 2,414
  • 6
  • 29
  • 46
  • 1
    see: http://stackoverflow.com/questions/34541532/is-angular-2s-router-broken-when-using-html5-routes – Langley Jan 22 '16 at 20:39
  • 1
    Possible duplicate of [Using Resolve In Angular2 Routes](http://stackoverflow.com/questions/33462532/using-resolve-in-angular2-routes) – Mike Jan 22 '16 at 21:12
  • I do not think my question is duplicate. Everywhere it is mentioned about handling the requests using alternative ways or using # techniques. I tried some other blogs which mention about `npm lite server` however I am unable to get answer what changes I need to have if I am deploying my app on IIS server. Each time I cannot run `npm lite` e.g. on QA server or staging. – Avi Kenjale Jan 22 '16 at 21:54
  • Try to redirect the route in IIS from MyVirtualApplication. – eesdil Jan 23 '16 at 19:34

2 Answers2

2

EDIT: IIS Setup for Url Rewriting:

You need to install this to make the following work: http://www.iis.net/downloads/microsoft/url-rewrite

First Step:

Second Step:

I found a link which explains the solution: https://stackoverflow.com/posts/12614072/

OLD:

While running any application built with Angular 2 outside of the development environment setup by npm, you have to replace <base href="/"> with this:

<script>document.write('<base href="' + document.location + '" />');</script>

Note: This is only for production or if running out of the npm environment.

Community
  • 1
  • 1
Bryan
  • 747
  • 1
  • 7
  • 19
  • I tried this same. and when I implementing this thru IIS, I am having issues. Just for my knowledge, have you tried from both `npm lite` and from `IIS` ? and it is running without any issues for you? – Avi Kenjale Jan 25 '16 at 15:03
  • @Avinash - I don't have **IIS** but I've found a solution. Check the edit to my answer. – Bryan Jan 25 '16 at 15:30
  • I think I have tough time with IIS and this HTML5 feature. I tried exactly same mention by your comments however no luck and on top of that link provided you is not available. Either broken or incomplete. I think for time being I have to go with `npm lite` server. Thank you for your efforts. – Avi Kenjale Jan 25 '16 at 19:41
  • After struggling with asp.net core request rewrite and mvc etc, I came over this solution. And I must say I like it very much. This way I don't have to publish the enormous Core app just for the silly request rewriting, and it is much easier to configure. – Snorre Aug 24 '16 at 14:37
-3

I Think I got my answer after basic understanding on nodejs and use of it with Angular2.

Basically, nodejs - expressjs itself is a web server and when we execute a command npm start web server starts and listing on a port which is defined. And it does not require any additional server.

Avi Kenjale
  • 2,414
  • 6
  • 29
  • 46