最初刷新页面时出现错误404。我通过实现hashlocationstrategy修复了这个问题,但现在当我刷新页面而不是错误404时,它会转到root index.html,这不是我想要的正确位置。相反,我希望它在当前页面上刷新。例如www.site.com/#/form并在刷新时保留在该页面上。可以用angular2中的hashlocationstrategy来完成吗?
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import {router} from './app.router';
import { AppComponent } from './app.component';
import { UsersComponent } from './users/users.component';
import { LocationStrategy, HashLocationStrategy } from '@angular/common';
import { UsercommentsComponent } from './usercomments/usercomments.component';
import { FormComponent } from './form/form.component';
@NgModule({
declarations: [
AppComponent,
UsersComponent,
UsercommentsComponent,
FormComponent,
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
router,
ReactiveFormsModule
],
providers: [ { provide: LocationStrategy, useClass: HashLocationStrategy }],
bootstrap: [AppComponent]
})
export class AppModule { }