无效的路由配置' login':必须提供以下其中一项(component或redirectTo或children或loadChildren)

时间:2016-11-04 05:56:36

标签: angular angular2-routing

我正在学习Angular 2,我使用RC7遇到了这个问题。

app.routing.ts:

import { ModuleWithProviders, NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
import { LoginRoutes } from './login/index';
import { DashboardRoutes } from './dashboard/index';

const routes: Routes = [
     ...LoginRoutes,
    ...DashboardRoutes
   //{ path:'', component: GridViewComponent }
];

@NgModule({
    imports: [RouterModule.forRoot(routes)],
    exports: [RouterModule],
    providers: []
})

export class Ng2PlayRoutingModule { }

login.routes.ts

import { LoginComponent } from './index';

export const LoginRoutes = [
    {
        path: 'login',
        component: LoginComponent
    },
    {   path: '', 
        redirectTo: 'dashboard/gridview', 
        pathMatch: 'full'
    }
];

dashboard.routes.ts

 import { DashboardComponent } from './index';
    import { GridRoutes } from './gridview/index';

    export const DashboardRoutes = [
        {
            path: 'dashboard',
            component: DashboardComponent,
            children: [
                ...GridRoutes
            ]
        }
    ];

此处,页面加载时会重定向到信息中心/ gridview 。并且它没有显示任何内容并在控制台中出现此错误

zone.js:388Unhandled Promise rejection: Invalid configuration of route 'login': one of the following must be provided (component or redirectTo or children or loadChildren) ; Zone: <root> ; Task: Promise.then ;

帮助我解决导致问题的原因。

修改

登录/ index.ts

export * from './login.component';
export * from './login.routes';

0 个答案:

没有答案