Reputation: 1175
I have the following web with angular 2 routing (using vs 2015 as my IDE)
however, whenever i refresh the page, i get this:
Therefore, whenever i want to hard refresh my page, i have to go to the error page first then i need to enter the following url: http://localhost:57831/index.html
Is there any solution so whenever i hard refresh, it always go to http://localhost:57831/index.html instead of http://localhost:57831/index.html/search?
thanks
Upvotes: 0
Views: 865
Reputation: 1175
found the answer from here: Angular 2 : 404 error occur when i refresh through Browser
in app.module.ts:
Add imports:
import { HashLocationStrategy, LocationStrategy } from '@angular/common';
And in NgMoudle provider, add:
{provide: LocationStrategy, useClass: HashLocationStrategy}
Upvotes: 1
Reputation: 71911
Besides that you should try to redirect all 404 request inside your VC2015 webserver to index.html
. If you have done that, there are two solutions for your problem.
web.conf
file of your VC2015 application. There you should find a httpRuntime
entryChange it to allow the :
, by removing the :
entry:
<system.web>
<httpRuntime requestPathInvalidCharacters="<,>,*,%,&,\,?"/>
</system.web>
Perhaps this file is located here:
%userprofile%\Documents\IISExpress\config\web.conf
:
inside your URL, use a dash (-
) or what ever is not illegal in the comma separated list above (I'd say go for this), there is a reason those characters are considered illegal:Upvotes: 0