Angular 4.1.3路由无法从父模块解析子模块

问题描述 投票:1回答:2

提前感谢您的帮助!!!!

你好,正如标题所说。我收到了以下错误....我正在尝试做一堆研究并弄清楚,但我做的任何事情似乎都有效。以下是一些重要文件,有没有人有这个问题的经验或看到问题? (此外错误来自ng服务和ng构建,但是ng服务它首先失败然后自动重建并且工作完美。所以它确实适用于ng服务但是因为第一个是失败我不能建立它(显然是主要问题)

ERROR in Could not resolve "patient.module" from "d:/Downloads/AngularApp/AngularApp/src/app/app.module.ts".

app.routing.ts

const patientRoutes: Routes = [
    {
        path: 'patient',
        loadChildren: 'app/patient/patient.module.ts#PatientModule',
    }
];

const nurseRoutes: Routes = [
    {
        path: 'nurse',
        loadChildren: 'app/nurse/nurse.module.ts#NurseModule',
    }
];


const appRoutes: Routes = [
    {
        path: '',
        redirectTo: 'auth',
        pathMatch: 'full'
    },
    {
        path: 'auth',
        component: AutenticationComponent
    },
    ...patientRoutes,
    ...nurseRoutes
];

export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes, {useHash: true});

patient.module.ts

import { NgModule }                     from '@angular/core';
import { CommonModule }                 from '@angular/common';
import { patientRouting }               from './patient.routing';

import { PatientDashboardComponent }    from './dashboard/patient-dashboard.component';


@NgModule({
              imports:      [
                  CommonModule,
                  patientRouting
              ],
              declarations: [
                  PatientDashboardComponent
              ]
          })
export class PatientModule { }

patient.routing.ts

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

import { PatientComponent }             from './patient.component';
import { PatientDashboardComponent }    from './dashboard/patient-dashboard.component';
import { PatientVideoComponent }             from './video/video-chat.component';

const patientRoutes: Routes = [
    {
        path: 'patient',
        component: PatientComponent,
        children: [
            {
                path: '',
                component: PatientVideoComponent,
                children: [
                    {
                        path: '',
                        component: PatientDashboardComponent,
                    }
                ]
            }
        ]
    }
];

export const patientRouting: ModuleWithProviders = RouterModule.forChild(patientRoutes);

角度cli.json

"apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": ["assets"],
      "index": "index.html",
      "main": "main.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.json",
      "prefix": "app",
      "mobile": false,
angular typescript angular2-routing
2个回答
2
投票

我终于找到了一些东西,这似乎有效。他们改变了他们的路由结构,而不是说应用程序/患者直接使用./patient例如。

https://github.com/angular/angular-cli/issues/3623


0
投票

应用程序/ DIR1 / DIR2 / ...

(假设路径模块在app目录中配置)到./dir1/dir2 / ...

可以解决这个问题:

const routes: Routes = [
  {
    path:'customers',
    loadChildren: './customers/customers.module#CustomersModule'

  },
  {
    path: 'orders',
    loadChildren: './orders/orders.module#OrdersModule'
  },
  {
    path:'contacts',
    loadChildren:'./contacts/contacts.module#ContactsModule'
  },
  { 
    path:'',
    redirectTo:'',
    pathMatch:'full'
  }  
];
© www.soinside.com 2019 - 2024. All rights reserved.