I am using angular application; I have no problem in running on localhost when I hosted my application on server. When I clicked the employee button it loads the employee details. However I refreshed the same page, I gives me 404 file or directory not found error.
I have fixed the following issue using hash approach.
This will make the links look like http://domain.com/#/page
for the url http://domain.com/page.
In app.module.ts, we need to import HashLocationStrategy,
LocationStrategy. And then in NgModule
Provider add {{provide: LocationStrategy, useClass:
HashLocationStrategy}}.
App.Module.Ts
import {
BrowserModule } from '@angular/platform-browser';
import { NgModule
} from '@angular/core';
import {
HashLocationStrategy, LocationStrategy } from '@angular/common';
@NgModule({
declarations: [
AppComponent,
],
imports: [
BrowserModule,
AppRoutingModule,
HttpClientModule,
],
providers: [SharedService,{ provide:
LocationStrategy, useClass: HashLocationStrategy}],
bootstrap: [AppComponent]
})
export class AppModule { }
Post your comments / questions
Recent Article
- FieldError: Cannot resolve keyword 'id' into field in Django project
- How to hide the ID field from the Django admin?
- It is impossible to add a non nullable field without specifying a default. Django error
- ImportError: cannot import name 'url' from 'django.conf.urls' - Django Error
- How to Enable Virtualization in BIOS Security Settings in Intel Processors For Android Studio?
- Dependency 'androidx.activity:activity:1.8.0' requires libraries and applications that depend on it.
- AttributeError: 'NoneType' object has no attribute 'get_text' - Python
- ModuleNotFoundError: No module named 'openpyxl' - Python
Related Article