代码之家  ›  专栏  ›  技术社区  ›  Smooth

未捕获错误:路由“feed”的配置无效。必须提供以下选项之一:component、redirectTo、children或loadChildren

  •  1
  • Smooth  · 技术社区  · 5 年前

    import { NgModule } from '@angular/core';
    import { Routes, RouterModule } from '@angular/router';
    import { DashboardComponent } from './dashboard/dashboard.component';
    import { VoteHistoryComponent } from './vote-history/vote-history.component';
    import { PollHistoryComponent } from './poll-history/poll-history.component';
    import { PollShowComponent } from './poll-show/poll-show.component';
    import sportTypes from '../assets/types/sport-types.json'
    
    const feedRoutes = sportTypes.types.map(type => {
      return { path: type.name, component: DashboardComponent }
    });
    
    const voteHistoryRoutes = sportTypes.types.map(type => {
      return { path: type.name, component: VoteHistoryComponent }
    });
    
    const pollHistoryRoutes = sportTypes.types.map(type => {
      return { path: type.name, component: PollHistoryComponent }
    });
    
    const pollShowRoutes = sportTypes.types.map(type => {
      return {
        path: type.name,
        children: [{
          path: ':id', component: PollShowComponent
        }]
      }
    });
    
    const routes: Routes = [
      { path: '', redirectTo: '/feed/football', pathMatch: 'full'},
      { path: 'feed',
        children: feedRoutes
      },
      { path: 'history',
        children: voteHistoryRoutes
      },
      { path: 'polls',
        children: pollHistoryRoutes
      },
      { path: 'poll',
        children: pollShowRoutes
      }
    ];
    
    @NgModule({
      imports: [RouterModule.forRoot(routes)],
      exports: [RouterModule]
    })
    export class AppRoutingModule { }
    
    0 回复  |  直到 5 年前