[英]Angular 2 - Fallback route not working
我有一個與此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
},
];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.