我有一个用这个 Angular 2 Webpack Starter 构建的 Angular2 项目但我无法让后备路线正常工作。在我的 app.routes.ts
我有:
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
},
];
关于javascript - Angular 2 - 后备路线不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42840310/