Angular 2.0.1 Router EmptyError: no elements in sequence

前端 未结 2 875
一个人的身影
一个人的身影 2020-12-20 23:38

I\'m having trouble getting Angular 2 routing to work. I am using Angular 2 and Webpack. In the Angular 2 webpack starter, I noticed they had webpack generating their html a

相关标签:
2条回答
  • 2020-12-21 00:32

    This bug is due to the last version of Angular's Router. Please remove revert back angular version or add pathMatch: 'full' to your routes.

    export const userRoutes = [
        { path: 'profile', component: ProfileComponent, pathMatch: 'full' },
        { path: 'login', component: LoginComponent, pathMatch: 'full' }
    ];
    
    
    export const appRoutes = [
        { path: '', redirectTo: '/events', pathMatch: 'full' },
        { path: 'user', loadChildren: './user/user.module#UserModule' }
    ];
    

    You can find the issue here

    0 讨论(0)
  • 2020-12-21 00:42

    Add pathMatch: 'full'

    { path: '', component: HomeComponent, pathMatch: 'full' },
    

    otherwise both routes

    { path: '', component: HomeComponent },
    { path: 'schedule', component: ScheduleComponent },
    

    match on route /schedule because '' matches, but doesn't consume anything from the route and then also 'schedule' matches.

    0 讨论(0)
提交回复
热议问题