我有一个使用HashLocationStrategy的Angular5应用程序。哈希确实出现在地址栏中,并且导航正常。但是,当我按F5键时,页面不会刷新。而是,它导航到应用程序的根目录。我的应用路由器在下面。
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { MessageListComponent } from './message-list/message-list.component';
import { PageNotFoundComponent } from './page-not-found/page-not-found.component';
import { LoginComponent } from './login/login.component';
import { AboutComponent } from './about/about.component';
import { AuthGuard } from './guards/auth.guard';
import { MessageDetailsComponent } from './message-details/message-details.component';
import { RedeliverComponent } from './redeliver/redeliver.component';
import { GraphComponent } from './graph/graph.component';
import { AccessDeniedComponent } from './access-denied/access-denied.component';
import { AdminGuard } from './guards/admin.guard';
import { ErrorManagerGuard } from './guards/error-manager.guard';
import { TestlistComponent } from './testlist/testlist.component';
import { TestdetailsComponent } from './testdetails/testdetails.component';
import { HashLocationStrategy, LocationStrategy } from '../../node_modules/@angular/common';
const appRoutes: Routes = [
{ path: 'testlist', component: TestlistComponent },
{ path: 'testdetails/:id', component: TestdetailsComponent },
{ path: 'login', component: LoginComponent },
{ path: 'accessDenied', component: AccessDeniedComponent },
{ path: 'about', component: AboutComponent },
{ path: 'graph', component: GraphComponent, canActivate: [AdminGuard] },
{ path: 'redeliver', component: RedeliverComponent, canActivate: [ErrorManagerGuard] },
{ path: 'list', component: MessageListComponent, canActivate: [AuthGuard] },
{ path: 'details/:id', component: MessageDetailsComponent, canActivate: [AuthGuard] },
{ path: '', redirectTo: '/list', pathMatch: 'full' },
{ path: '*', component: PageNotFoundComponent }
]
@NgModule({
imports: [
RouterModule.forRoot(appRoutes, { useHash: true , enableTracing:true})
],
exports: [RouterModule],
providers: [
{ provide: LocationStrategy, useClass: HashLocationStrategy }
]
})
export class AppRoutingModule { }
我不知道发生了什么。我创建了一个新项目来测试HashLocationStrategy,并且刷新在新项目上工作正常。我还在现有项目中添加了两个虚拟组件,以查看是否有任何组件引起了该问题,但虚拟组件也不起作用。有人可以帮我解决刷新行为吗?