角路由:主页URL应为http:// localhost:4200 /

时间:2019-03-08 07:08:06

标签: angular angular-routing

我已经在项目中完成了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
 }
];

谢谢您的任何帮助。

1 个答案:

答案 0 :(得分:1)

您可以通过以下方式实现同​​样的目标

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,
      },
    ]
  }
];