在定义 Angular 路由时,需要通过配置 useHash
属性将哈希符号作为路由模式的标志。具体操作如下:
RouterModule
和 Routes
:import { RouterModule, Routes } from '@angular/router';
useHash
属性为 true
:const routes: Routes = [
{ path: '', redirectTo: '/home', pathMatch: 'full' },
{ path: 'home', component: HomeComponent },
{ path: 'about', component: AboutComponent },
{ path: '**', component: PageNotFoundComponent }
];
@NgModule({
imports: [RouterModule.forRoot(routes, { useHash: true })],
exports: [RouterModule]
})
export class AppRoutingModule { }
http://localhost:4200/#/about