Angular2 + redirectTo路由不起作用

时间:2018-06-29 10:07:13

标签: angular angular5

当我的Web应用程序加载到浏览器中时,我的地址栏显示为“ localhost:5000”。它不会加载/重定向到我的“常见问题”页面,但显示一个空白页面。我似乎无法想到发生这种情况的任何原因。没有控制台错误。有人可以帮忙吗? Snapshot of my console output is here. 我的路线配置如下:

RouterModule.forRoot(
      [
        {path: '', redirectTo: '/home', pathMatch: 'full'},
  { path: '', component: GeneralComponent,
children: [
  { path: 'home', loadChildren: './thrive-home/thrive-home.module#ThriveHomeModule'},
  { path: 'resources', loadChildren: './thrive-resources/thrive-resources.module#ThriveResourcesModule'},
  { path: 'services', loadChildren: './thrive-services/thrive-services.module#ThriveServicesModule'},
  { path: 'profiles', loadChildren: './thrive-profiles/thrive-profiles.module#ThriveProfilesModule'},
  { path: 'chat', loadChildren: './chat/chat.module#ChatModule'},
  { path: 'user', loadChildren: './thrive-user/thrive-user.module#ThriveUserModule'},
  { path: 'contact', component: ContactUsComponent},
  { path: 'faq', component: FaqComponent },
  { path: 'privacy-policy', component: PrivacyPolicyComponent},
  { path: 'confirm-email', component: ConfirmEmailComponent },
  { path: 'book-appointment', component: BookAppointmentComponent }
]
  },
        ],{ enableTracing: true })

2 个答案:

答案 0 :(得分:0)

在重定向到url的地方删除/,并将其放置在已定义的路由之后(例如,在**之前)。

还要确保在app.component.html文件中有<router-outlet>,并且要在AppRouterModule导入列表中导入AppModule

答案 1 :(得分:0)

删除/

RouterModule.forRoot(
      [
        {path:'', redirectTo:'faq', pathMatch:'full'},
        { path: 'faq', component: FaqComponent },
        { path: 'privacy-policy', component: PrivacyPolicyComponent},
        { path: 'confirm-email', component: ConfirmEmailComponent },
        { path: '**', component: PrivacyPolicyComponent }
        ],{ enableTracing: true })