Angular2 HashLocationStrategy始终重定向到根目录
我在我的Angular2 HashLocationStrategy始终重定向到根目录,angular,angular2-routing,Angular,Angular2 Routing,我在我的应用程序模块中使用HashLocationStrategy,如下所示: @NgModule({ imports: [ BrowserModule, AppRoutingModule ], declarations: [ AppComponent ], providers: [{provide: LocationStrategy, useClass: HashLocationStrategy}], bootstrap: [ AppComp
应用程序模块中使用HashLocationStrategy
,如下所示:
@NgModule({
imports: [
BrowserModule,
AppRoutingModule
],
declarations: [ AppComponent ],
providers: [{provide: LocationStrategy, useClass: HashLocationStrategy}],
bootstrap: [ AppComponent ]
})
我的应用程序路由。模块定义为:
export const routes: Routes = [
{ path: '', redirectTo: 'home', pathMatch: 'full'},
{ path: 'live', loadChildren: 'app/live/live.module#LiveModule' }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
当我导航到根url时,它会将我正确重定向到主页
,但是当我尝试导航到/live
时,我仍然会被重定向到主页。当我使用/#/live
时,它会正确加载LiveModule
知道为什么会发生这种情况吗?根据seed,@NgModule中导入的哈希策略语法如下:
forRoot(rootRouterConfig,{useHash:true})
希望对您有所帮助。根据seed,@NgModule中的导入有如下哈希策略语法:
forRoot(rootRouterConfig,{useHash:true})
希望它有帮助问题不在于如何使用HashLocation,而在于它总是将我重定向回主页问题不在于如何使用HashLocation,但它总是将我重定向回主页。你有没有找到解决方法?我在生产中遇到了hashlocationstrategy问题,当在URL上第二次按enter键时没有调用我的后端。你有没有找到解决方法?我在生产中遇到了hashlocationstrategy问题,当在URL上第二次按enter键时没有调用我的后端后端