Angular 2 - 后退路线不起作用

Angular 2 - 后退路线不起作用

问题描述:

我有一个用此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。我怎样才能让我的顶级版本工作,或者我可以做些什么来完成这项工作?

所以,我只是试了一下,似乎你不能使用懒惰的路线来设置你的回退页面。这应该工作:

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

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