0

我无法直接前往子路线。我的网址是http://localhost:4201/home/profile但路由器跟踪以 url: '/home' 而不是 url: '/home/profile' 开头

路由器事件:NavigationStart platform-b​​rowser.es5.js:1028 NavigationStart(id: 1, url: '/home') platform-b​​rowser.es5.js:1028 NavigationStart {id: 1, url: "/home"}

const feedsRoutes: Routes = [
    {
        path: '',
        component: HomeComponent,
        children: [
            { path: 'home', redirectTo: '', pathMatch: 'full' },
            { path: '', loadChildren: '../feeds-home/feeds-home.module#FeedsHomeModule' },
            { path: 'business', loadChildren: '../business-home/business-home.module#BusinessModule' },
            { path: 'people', loadChildren: '../people-home/people-home.module#PeopleModule' },
            { path: 'profile', loadChildren: '../profile-home/profile-home.module#ProfileModule' },
            { path: 'settings', component: SettingsComponent, data: { title: 'Settings' } }
        ]
    }
];

这是由于将子路由加载为模块吗?

4

1 回答 1

0

尝试使用 '/home/profile' 在数组中显式创建一个路由条目,并将该条目放在 { path: 'home', redirectTo: '', pathMatch: 'full' } 之前。这是因为 Angular 从头到尾读取它们,并且只要任何条目评估为真,就会退出。否则,在每种情况下都会导航到“家”而不是“家/个人资料”。

于 2018-07-10T18:27:52.857 回答