Angular路由:主页URL应该是http://localhost:4200/

Angular routing: Home page URL should be http://localhost:4200/

我在我的项目中完成了 URL 路由。当我重定向到主页时 URL 变成 http://localhost:4200/home.

我希望我的主页 URL 是 http://localhost:4200/ 而不是 http://localhost:4200/home

我的 app.routing.ts 文件:

    const routes: Routes = 
    [
     {
      path: '',
      redirectTo: 'home',
      pathMatch: 'full'
     },
     {
      path: '',
      component: LayoutComponent,
      children: [
       {
         path: 'home',
         loadChildren: './home/home.module#HomeModule'
       }
      ]
     }
    ];

下面是 home.routing.ts 文件:

    const routes: Routes = [
     {
      path: '',
      component: HomeComponent
     }
    ];

任何帮助将不胜感激,谢谢。

您可以通过以下方式实现同​​样的效果

app.routing.ts

const routes: Routes = [
  {
    path: '',
    loadChildren:
      './home/home.module#HomeModule'
  },
  {
    path: '',
    loadChildren:'./another/another.module#AnotherModule'
    
  }
  
];

并在 Home 模块路由器中

const routes: Routes = [
  {
    path: '',
    component: LayoutComponent,
    children: [
      {
        path: '',
        component: HomeComponent,
       
      },
      {
        path: 'other',
        component: otherComponent,
      },
    ]
  }
];