Reputation: 55
have error 404 in redirect angular app via the address bar in browser but when does this work in the browser after running angular app via ng serve command everything is ok. my config in Nginx is:
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root “D:\Tools\nginx-1.16.0\nginx-1.16.0\html”;
try_files $uri $uri/ /index.html?$args;
}
Note: Currently Define base in Index html file
<base href="/">
Upvotes: 0
Views: 348
Reputation: 1213
You have two options, you can use any that suits you well:
I don't know the config setting for Nginx but for IIS. You could find some equivalent of below:
<system.webServer>
<rewrite>
<rules>
<rule name="redirect all requests" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false"/>
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false"/>
</conditions>
<action type="Rewrite" url="samcds/index.html" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
In your app module, add below providers:
providers: [Location, {provide: LocationStrategy, useClass: HashLocationStrategy}],
for referenece https://angular.io/api/common/HashLocationStrategy
Upvotes: 2