3
votes

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.

2
Possible duplicate of Using Resolve In Angular2 Routes - Mike
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
Try to redirect the route in IIS from MyVirtualApplication. - eesdil

2 Answers

2
votes

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.

-3
votes

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.