【发布时间】:2019-03-13 19:05:10
【问题描述】:
我建立了一个网站,其中模板已被划分为组件。模板的页眉和页脚在 main.component.html 文件中,主体注入 router-outlet。
导航中唯一改变的部分是正文。页眉和页脚保持不变。共享 storeid 查询参数以动态构建正文。
我遇到的问题是我必须从 main.component.ts 文件中获取 storeid 查询参数。我不知道如何使用我当前的路线配置来做到这一点。
以下是路线配置:
const routes: Routes = [
{
path: '',
component: HomeLayoutComponent, // HOME PAGE
children: [
{ path: 'home', component: HomeComponent },
{ path: '', redirectTo: '/home', pathMatch: 'full' },
]
},
{
path: '', // I TRIED ':storeid' here but negative
component: MainLayoutComponent, // MAIN LAYOUT IS DIVIDED AS DESCRIBED IN QUESTION. THIS IS THE STOREID I HAVE TO FETCH FROM HERE
children: [
{ path: 'event-details/:storeid', component: EventDetailsComponent }, // SO AS HERE TOO.
{ path: '', redirectTo: '/home', pathMatch: 'full' },
]
},
{ path: 'error-404', component: Error404PageComponent },
{ path: 'error-500', component: Error500PageComponent },
{ path: '**', component: HomeComponent }
];
谢谢
【问题讨论】: