以下路线配置有什么问题?即使有**
的路线,我也始终导航到app/jungle
。
import {bootstrap} from '@angular/platform-browser-dynamic';
import { RouterConfig, provideRouter } from '@angular/router@3.0.0-beta.2'
import {App} from './app';
import { HomeComponent } from './home.component';
import { JungleComponent } from './jungle.component';
import { NotFoundComponent } from './not-found.component';
const APP_ROUTES: RouterConfig = [
{
path: '', pathMatch: '', redirectTo: 'app/home'
},
{
path: 'app/', pathMatch: '', redirectTo: 'app/home'
},
{
path: 'app/home', component: HomeComponent
},
{
path: 'app/jungle', component: JungleComponent
},
{
path: '**', component: NotFoundComponent
}
]
bootstrap(App, [provideRouter(APP_ROUTES)])
.catch(err => console.error(err));
Here是一名傻瓜。 我正在使用@ angular / router @ 3.0.0-beta.2
答案 0 :(得分:3)
''
是pathMatch
的无效值。
pathMatch
支持full
和prefix
。 prefix
是默认值。
前两条路线的设置为'full'
:
{
path: '', pathMatch: 'full', redirectTo: 'app/home'
},
{
path: 'app/', pathMatch: 'full', redirectTo: 'app/home'
},
{
path: 'app/home', component: HomeComponent
},
{
path: 'app/jungle', component: JungleComponent
},
{
path: '**', component: NotFoundComponent}
]
更新(根据以下评论)
我不确切知道为什么尾随/
使它工作但我会使用无组件父路线而不是像
const APP_ROUTES: RouterConfig = [
{ path: '', pathMatch: 'full', redirectTo: 'app/home' },
{ path: 'app', children: [
{ path: '', pathMatch: 'full', redirectTo: 'home' },
{ path: 'home', component: HomeComponent },
{ path: 'jungle', component: JungleComponent },
]},
{ path: '**', component: NotFoundComponent }]