2017-03-16 171 views
1

我有一個用此Angular 2 Webpack Starter構建的Angular2項目,但我無法讓後備路線正常工作。在我app.routes.ts我:Angular 2 - 後退路線不起作用

import { Routes } from '@angular/router'; 
import { HomeComponent } from './home'; 
import { DataResolver } from './app.resolver'; 

export const ROUTES: Routes = [ 
    { 
    path: '', 
    component: HomeComponent 
    }, 
    { 
    path: 'getstarted', loadChildren: './getstarted#GetStartedModule' 
    }, 

    ... 
    { 
    path: 'notfound', loadChildren: './notfound#NotFoundModule' 
    }, 
    { 
    path: '**', loadChildren: './notfound#NotFoundModule' 
    }, 
]; 

not found通路上正常工作,但後備路線(**)無法正常工作。而不是顯示NotFoundModule它根本不加載模塊,我沒有得到任何錯誤。然而,當我這樣做是正確重定向:

... 
    { 
    path: 'notfound', loadChildren: './notfound#NotFoundModule' 
    }, 
    { 
    path: '**', redirectTo:'/notfound', pathMatch: 'full' 
    }, 
]; 

我不想雖然重定向,因爲我不想被重定向到URL更改爲/notfound。我怎樣才能讓我的頂級版本工作,或者我可以做些什麼來完成這項工作?

回答

2

所以,我只是試了一下,似乎你不能使用懶惰的路線來設置你的回退頁面。這應該工作:

export const ROUTES: Routes = [ 
    { 
    path: '', 
    component: HomeComponent 
    }, 
    { 
    path: 'getstarted', loadChildren: './getstarted#GetStartedModule' 
    }, 

    ... 
    { 
    path: 'notfound', loadChildren: './notfound#NotFoundModule' 
    }, 
    { 
    path: '**', component : NotFoundComponent 
    }, 
];