繁体   English   中英

Angular2 + redirectTo路由不起作用

[英]Angular2+ redirectTo route not working

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

 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 }) 

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

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

删除/

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 })

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM