[Method 1] Add useHash to src\app\app-routing.module.ts
@NgModule({
...
imports: [RouterModule.forRoot(routes, { useHash: true })],//使用hash网址模式
...
})
[Method 2] Modify the following providers in src\app\app.module.ts
@NgModule({
...
providers: [
{ provide: LocationStrategy, useClass: HashLocationStrategy } // hash模式
// {provide: LocationStrategy, useClass: PathLocationStrategy} // 无#及h5 history模式
],
...
})
Note: Method 2 has a higher priority than method 1. If {provide: LocationStrategy, useClass: PathLocationStrategy} and useHash:true are set at the same time, the hash mode will not take effect; similarly, if { provide: LocationStrategy, useClass: HashLocationStrategy } and useHash: false, the hash mode will take effect instead
Extended reading