2017-03-19 128 views
1


我想創建一些延遲加載的路由。但我不能擺脫錯誤找不到模塊(Angular 2)

的找不到模塊應用/搜索/ search.module

文件夾「搜索」是在「應用程序」文件夾中,路徑是正確的。它在沒有webpack的情況下工作,並且在webpack配置後開始這個問題。
它工作沒有延遲加載。
問題在哪裏?

app.module.ts

import { NgModule }  from '@angular/core'; 
import { BrowserModule } from '@angular/platform-browser'; 
import { AppComponent } from './app.component'; 
import { RouterModule, Routes } from '@angular/router'; 

const appRoutes: Routes = [ 
    { path: 'search', loadChildren: 'app/search/search.module#SearchModule' }, 
    { path: '**', redirectTo: '/search' } 
]; 

@NgModule({ 
    imports: [ 
    BrowserModule, 
    RouterModule.forRoot(appRoutes) 
    ], 
    declarations: [ AppComponent ], 
    bootstrap: [ AppComponent ] 
}) 
export class AppModule { } 

search.module.ts

import { NgModule }  from '@angular/core'; 
import { Routes, RouterModule } from '@angular/router'; 
import { SearchComponent } from "./search.component"; 
import { LocationsComponent } from "./locations/locations.component"; 
import { CommonModule } from "@angular/common"; 
import { GoogleMapsService } from "../shared/services/google-maps.service"; 

const routes: Routes = [ 
    { path: '', component: SearchComponent }, 
    { path: '**', redirectTo: '' } 
]; 

@NgModule({ 
    imports: [ 
    CommonModule, 
    RouterModule.forChild(routes) 
    ], 
    exports: [ 
    RouterModule 
    ], 
    declarations: [ SearchComponent, LocationsComponent ], 
    providers: [ GoogleMapsService ] 
}) 
export class SearchModule { } 

回答

0

我想你應該包括你search.module.tsapp.module.tsdeclarationsSearchModule

或嘗試將./添加到此{ path: 'search', loadChildren: 'app/search/search.module#SearchModule' },。爲了得到結果如下:

{ path: 'search', loadChildren: './app/search/search.module#SearchModule' }, 
0

試試這個

const routes: Routes = [ 
     {path: '', component: SearchComponent, children: [ 
      {path: '**', redirectTo: ''} 
     ]} 
    ] 
相關問題