typescript - Angular 2 application running on iis returns not found when reload -


i made new page in iis. connected physical path angular 2 app source.

when access page localhost:port page normally.

when switch other view, e.g. localhost:port/employees, works ok @ first, when reload page returns http-404 error same url. had problem? think has angular 2 routing.

also iis gives response:

most probable causes: directory or file specified not exist on web server.

it not problem angular routing . thing has handled on server side. when doing refresh server should redirect base path.

by default angular 2 applications don't use hash (#) prefix on urls, effect of if try navigate directly deep link in angular app or refresh internal page may 404 page not found error. because web server receiving request looks resource matching full url on server, doesn't exist because angular portion of url refers route in angular application , needs handled in client browser.

one work around in angular can use hashlocationstrategy .

@ngmodule({     declarations: [appcomponent],     imports: [browsermodule],     providers: [{provide: locationstrategy, useclass: hashlocationstrategy}],     bootstrap: [appcomponent], }) 

angular 2 + iis - url rewrite rule prevent 404 error after page refresh

the way fix rewriting virtual urls main angular 2 index.html file.

<rewrite>   <rules>     <rule name="angular" stopprocessing="true">       <match url=".*" />       <conditions logicalgrouping="matchall">         <add input="{request_filename}" matchtype="isfile" negate="true" />         <add input="{request_filename}" matchtype="isdirectory" negate="true" />       </conditions>       <action type="rewrite" url="/" />     </rule>   </rules> </rewrite> 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -