I'm developing an Angular 4 application. I intended to use the HashLocationStrategy
but its not working(# is not appearing in the URLs). Below is my app routing module:
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { DashboardPage } from './dashboard-page/component';
import { AccountPage } from './acct-page/component';
const appRoutes: Routes = [
{ path: 'dashboard', component: DashboardPage },
{ path: 'accounts/:number', component: AccountPage},
{ path: '', redirectTo: '/dashboard', pathMatch: 'full' },
];
@NgModule({
imports: [RouterModule.forRoot(appRoutes, { enableTracing: false, useHash: true })],
exports: [RouterModule],
providers: []
})
export class AppRoutingModule { }
Below is my app.module.ts:
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule, Routes } from '@angular/router';
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common'
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { HttpClientModule } from '@angular/common/http';
import { NgxChartsModule } from '@swimlane/ngx-charts';
import { DataTableModule } from "angular2-datatable";
import {
MatToolbarModule, MatToolbarRow, MatIconModule, MatSidenavModule, MatListModule, MatButtonModule,
MatCardModule, MatMenuModule, MatGridListModule, MatInputModule, MatDatepickerModule, MatNativeDateModule,
MatTableModule, MatTabsModule, MatCheckboxModule
} from '@angular/material';
import { MatSelectModule } from '@angular/material/select';
import {MatExpansionModule} from '@angular/material/expansion';
import { AppComponent } from './app-component/app.component';
import { AppRoutingModule } from './app-routing.module';
import { DashboardPage } from './dashboard-page/component';
import { AccountPage } from './acct-page/component';
@NgModule({
declarations: [
AppComponent, DashboardPage, BreadcrumbComponent, AccountPage
],
imports: [
AppRoutingModule, RouterModule, BrowserModule, HttpClientModule, BrowserAnimationsModule, MatToolbarModule, MatIconModule,
MatSidenavModule, MatListModule, MatButtonModule, MatCardModule, MatInputModule, CommonModule,
MatMenuModule, MatGridListModule, DataTableModule, FormsModule, ReactiveFormsModule, MatDatepickerModule,
MatNativeDateModule, MatTableModule, MatTabsModule, MatExpansionModule, MatCheckboxModule, MatSelectModule, NgxChartsModule
],
providers: [],
bootstrap: [AppComponent],
entryComponents: [XMLContentDialog]
})
export class AppModule {
}
I used RouterModule.forRoot(appRoutes, { enableTracing: false, useHash: true })
for enabling the hash location strategy, but its not working. Am I missing something here?
[EDIT]
Updated 'title' to reflect the root cause