When I refresh a page like this (/category/details/1)
I got an error
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable
I solved the problem by using Hash Location
{provide: LocationStrategy, useClass: HashLocationStrategy}
in providers in app.module but it made the routing link like this (#/category/details/1) and that is not accepted.
In .NET Core, I tried to implement this function in the program.cs
var app = builder.Build();
// fallback route to serve index.html for all deep links
app.Use(async (context, next) =>
{
await next();
// if no response was sent back by other middleware, and the request path
//doesn't start with "/api",serve the index.html file
if (context.Response.StatusCode == 404 &&
!context.Request.Path.Value.StartsWith("/api"))
{
context.Request.Path = "/index.html";
await next();
}
});
And in Angular - I created a web.config file and placed it next to index.html file in the (dist) folder and implemented
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Angular Routes" 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>
</system.webServer>
</configuration>
and added
// in the app.module
{ provide: LocationStrategy, useClass: PathLocationStrategy },
But I still got this error:
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
This is the response header:
Accept-Ranges: bytes
Content-Encoding: gzip
Content-Length: 4115
Content-Type: text/html
ETag: W/"0e9ce283e83d91:0"
Server: Microsoft-IIS/10.0
Vary: Accept-Encoding
X-Powered-By: ASP.NET