Angular 2 RC5无法匹配任何路线:'文件'

时间:2016-08-15 14:12:08

标签: angular

我正在将我的应用升级到RC5并遇到了一些困难。

在我的app.routing.ts中,我有:

import { Routes, RouterModule } from '@angular/router';

export const appRoutes: Routes = [
{ path: '', redirectTo: '/home', pathMatch: 'full'  },
{ path: 'home',  loadChildren: './app/home/home.module#HomeModule' },
{ path: 'documents',  loadChildren: './app/documents/documents.module#DocumentsModule' },
{ path: 'food',  loadChildren: './app/food/food.module#FoodModule' },
{ path: 'themes',  loadChildren: './app/themes/themes.module#ThemesModule' },
{ path: 'about',  loadChildren: './app/about/about.module#AboutModule' }];

export const appRoutingProviders: any[] = [];

export const routing = RouterModule.forRoot(appRoutes);

以下是路由器链接:

getLoggedInMenu() {
    return [
   {
      label: 'Home',
      routerLink: ['']
   }, {
      label: 'Documents',
      routerLink: ['/documents']
   }, {
      label: 'Tools',
      Items: [
      {
         label: 'Food',
         routerLink: ['/food']
      }, {
         label: 'Themes',
         routerLink: ['/themes']
      } ]
   },
   {
     label: 'About',
     routerLink: ['/about']
   }];
}

在food.routing.ts:

import { RouterModule }  from '@angular/router';
import {FoodComponent} from './food.component';

export const routing = RouterModule.forChild([
  { path: 'food', component: FoodComponent}]);

在themes.routing.ts中:

import { RouterModule }  from '@angular/router';
import {ThemesComponent} from './themes.component';

export const routing = RouterModule.forChild([
{ path: 'themes', component: ThemesComponent}]);

这两条路线运作良好。但是这两条路线没有:

在document.routing.ts中:

import { RouterModule }  from '@angular/router';
import {DocumentsComponent} from './documents.component';

export const routing = RouterModule.forChild([
 { path: 'documents', component: DocumentsComponent}]);

错误:EXCEPTION:错误:未捕获(在承诺中):错误:无法匹配任何路线:'文档'

在about.routing.ts:

import { RouterModule }  from '@angular/router';
import {AboutComponent} from './about.component';

export const routing = RouterModule.forChild([
  { path: 'about', component: AboutComponent}]);

错误:EXCEPTION:错误:未捕获(在承诺中):错误:无法匹配任何路线:' about'

每个app目录都是相同的。每个包含:

name.component.ts
name.component.css
name.component.html
name.module.ts
name.routing.ts

除了名称之外,每个内容都相同。

有人看错了吗?

1 个答案:

答案 0 :(得分:0)

经过一系列的阴谋之后,我注意到app.module.ts有工作模块路由的导入和失败的导入。导入它们并将它们添加到app.module导入部分修复了问题,所有路线现在都在工作。