【问题标题】:How can I hide the path from the url in Angular?如何在 Angular 中隐藏 url 的路径?
【发布时间】:2021-04-25 18:20:51
【问题描述】:

我正在开发一个 Angular 项目,我想隐藏 URL 中的路径。我不使用导航。这就是我需要的是当我进入站点时只看到www.hgshgs.gr 而不是www.hgshgs.gr/pages/dashboard。有没有办法做到这一点?

page-routing.module.ts

const routes: Routes = [{

  path: '',
  component: PagesComponent,
  children: [
    {
      path: 'dashboard',
      component: ECommerceComponent,
      
    },
    {
      path: 'iot-dashboard',
      component: DashboardComponent,
      
    },
    
    
    {
      path: '',
      redirectTo: 'iot-dashboard',
      pathMatch: 'full',
    },
    
    {
      path: '**',
      component: NotFoundComponent,
    },
  ],

}];
@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule],
})

【问题讨论】:

  • 你说你不使用导航,然后继续显示路由定义。
  • @MichaelD 我的意思是我没有可以在其他组件上导航的按钮。
  • 如果不想路由,可以在 app.compoment.html 中使用组件选择器。

标签: angular url path hide


【解决方案1】:

声明Router.forRoot时可以如下使用

imports: [ RouterModule.forRoot(routes, { initialNavigation : false }) ]

【讨论】:

  • 非常感谢您的回答,我有 RouterModule.forChild(routes) 并且无法添加任何属性
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-05-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-03
  • 1970-01-01
相关资源
最近更新 更多