我hash在我的路由器中使用过,例如当我导航时FrameworkModule,url 显示如下
http://localhost:4024/#/framework#,它在 url 的末尾添加哈希,当我刷新页面时,url 变成这样http://localhost:4024/#/framework%23,最后的哈希更改为%23并重定向至NotFoundComponent
export const routes: Routes = [
{
path: '',
component: PagesComponent, children: [
{ path: '', component: HomeComponent, data: { title: "Accueil" } },
{ path: 'framework', loadChildren: '@framework/framework.module#FrameworkModule', data: { title: "" } }
]
},
{ path: '**', component: NotFoundComponent }
];
@NgModule({
imports: [RouterModule.forRoot(routes, { useHash: true })],
exports: [RouterModule]
})
export class AppRoutingModule { }
@NgModule({
imports: [
AppRoutingModule
providers: [ { provide: LocationStrategy, useClass: HashLocationStrategy } ]
bootstrap: [AppComponent],
})
export class AppModule { }
框架路由
const routes: Routes = [
{ path: '', component: ListFrameworkComponent, pathMatch: 'full' }
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class FrameworkRoutingModule { }