Angular应用网址显示“#”,是否可以删除它?

时间:2019-08-13 00:54:45

标签: angular

我的角度应用程序URL显示# 我不想显示#,也不知道如何删除它。

这是信息中心页面的网址-http://localhost:4200/#/dashboard

我想找到一种使其变得像-this http://localhost:4200/dashboard

app.routing.module

const routes: Routes = [
    {
        path: '',
        redirectTo: 'dashboard',
        pathMatch: 'full',
    }, {
        path: '',
        component: AdminLayoutComponent,
        children: [{
            path: '',
            loadChildren: './layouts/admin-layout/admin-layout.module#AdminLayoutModule'
        }]
    }
];

@NgModule({
    imports: [
        CommonModule,
        BrowserModule,
        RouterModule.forRoot(routes, {
            useHash: true
        })
    ],

admin.routing.module

export const AdminLayoutRoutes: Routes =[
    { path: '', component: DashboardComponent },
    { path: 'dashboard', component: DashboardComponent },
    { path: 'connecter', component: ConnecterComponent },
    { path: 'inscrire', component: InscrireComponent },
    { path: 'bibliography', component: BibliographyComponent },
    { path: 'user-profile', canActivate: [AuthGuard], component: UserProfileComponent },
    { path: 'produits', canActivate: [AuthGuard], component: ProduitViewComponent },
    { path: 'produits/view/:id', canActivate: [AuthGuard], component: SingleProduitComponent },
    { path: 'commandes', canActivate: [AuthGuard], component: CommandesViewComponent },
    { path: 'commandes/view/:id', canActivate: [AuthGuard], component: SingleCommandeComponent },
    { path: 'produits/new', canActivate: [AuthGuard], component: ProduitFormComponent },
    { path: 'typography', component: TypographyComponent },
    { path: 'icons', component: IconsComponent },
    { path: 'notifications', component: NotificationsComponent },
    { path: '**', component: NotFoundComponent },
];

@NgModule({
  imports: [
  CommonModule,
  RouterModule.forChild(AdminLayoutRoutes),
]})

1 个答案:

答案 0 :(得分:1)

在路由器模块中,您具有以下内容

RouterModule.forRoot(routes, {
  useHash: true
})

删除useHash: true,使其现在看起来像这样

RouterModule.forRoot(routes)