Angular 角度:有些路由使用PathLocationStrategy,但有些路由使用HashLocationStrategy

Angular 角度:有些路由使用PathLocationStrategy,但有些路由使用HashLocationStrategy,angular,angular2-routing,angular2-services,angular-routing,angular-router,Angular,Angular2 Routing,Angular2 Services,Angular Routing,Angular Router,我的应用程序中有4条路线 import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; export const pageRoutes: Routes = [ {path: '', redirectTo: 'home', pathMatch: 'full'}, {path: 'home', component: HomeComponent}, {pa

我的应用程序中有4条路线

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

export const pageRoutes: Routes = [
  {path: '', redirectTo: 'home', pathMatch: 'full'},
  {path: 'home', component: HomeComponent},
  {path: 'transaction', loadChildren: './app/transaction.module#TransactionModule'},
  {path: 'evidence', loadChildren: './app/evidence.module#EvidenceModule'}
];

@NgModule({
  imports: [RouterModule.forRoot(pageRoutes)],
  exports: [RouterModule],
})
export class AppRoutingModule {}
在app.routes中,我没有对
LocationStrategy
进行任何特定设置。因为对于
事务
路由,我想使用angular2默认的PathLocationStrategy,它不允许用户刷新页面

但是对于
证据
路线,我实际上希望用户能够刷新页面。所以我想在这里使用HashLocationStrategy

这是证据传送模块

    @NgModule({

          imports: [RouterModule.forChild([
            {path:':sessionId', component: EvidenceComponent}
            { path: '**', redirectTo: '/404' },
            { path: '404', component: PageNotFoundComponent}
          ])], 
          exports: [RouterModule],
          providers: [{provide: LocationStrategy, useClass: HashLocationStrategy}]

    })
    export class EvidenceRoutingModule {}
我想在
证据路由中添加
提供程序:[{provide:LocationStrategy,useClass:HashLocationStrategy}]
以启用HashLocationStrategy并仅应用于此路由

但一旦我把它放在那里,整个应用程序将采用HashLocationStrategy,它也适用于事务路由

我找不到解决这个问题的好办法

对这个问题有什么建议吗


非常感谢

不能对不同的路由使用不同的
定位策略
,此设置适用于
路由器
,而不是路由,并且一个应用程序只能有一个路由器

您应该确保服务器配置正确,然后重新加载将适用于所有路由,即使使用
PathLocationStrategy

确保您的服务器配置为支持HTML5 pushState。
这只意味着服务器返回
index.html
请求未知资源