I have facing a problem 404 page not found in production build when refresh a page.
Build working fine with #
routing RouterModule.forRoot(routes, { useHash: true })
. But I want a pretty route without #
My module look like
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule,
HttpClientModule,
CoreModule,
AppRoutingModule,
AuthModule
],
providers: [
{
provide: HTTP_INTERCEPTORS,
useClass: HttpInterceptorService,
multi: true
}
],
bootstrap: [AppComponent]
})
Create .htaccess file in your index.html location
Note:RewriteBase /example/example is a your index.html base url
<base href="/example/example/">
The reason why 404 Not Found is showing on page refresh is that all Angular routes should be served via the index.html file.
You can fix this issue by adding a .htaccess file (in the same directory where the index.html resides) with the following contents.
Follow below link for further details regarding deploying production build to Apache:
https://github.com/mgechev/angular-seed/wiki/Deploying-prod-build-to-Apache-2
Deep urls are called SPA support, by default node's http-server doesn't support, but it can be enabled this way-
For Apache
For Nginx
For IIS
For GitHub pages
For Firebase Hosting
Source