[英]Can two components be abstract in Angular2 Router
I have three components:我有三个组成部分:
root
) that is a component bootstraps with app module.root
) 是带有 app 模块的组件引导程序。toolbar
) that contains toolbar for all it's children.toolbar
)包含所有子工具栏。dashboard
) that is first real page.dashboard
)是第一个真实页面。 So the root
and toolbar
should not have it's own URL, and dashboard
should.所以
root
和toolbar
不应该有自己的 URL, dashboard
应该。 At the resulting HTML I expect that they are put into each other in the following way:在生成的 HTML 中,我希望它们以下列方式相互放入:
<root>
<toolbar>
...some toolbar inner code
<dashboard>
...dashboard page code
</dashboard>
</toolbar>
</root>
And all of this code should be loaded by single URL: http:///dashboard所有这些代码都应该通过单个 URL 加载:http:///dashboard
Now I have following code:现在我有以下代码:
root
module routing root
模块路由
const rootRoutes: Routes = [
{path: '', component: ToolbarComponent},
];
toolbar
module routing toolbar
模块路由
const toolbarRoutes: Routes = [
{path: 'dashboard', component: DashboardComponent},
];
It works, but replaces toolbar
component with dashboard
.它可以工作,但用
dashboard
替换toolbar
组件。
How should I write my Routes
arrays to fulfil this demand?我应该如何编写我的
Routes
数组来满足这个需求? With ui-router
and deprecated component router
on AngularJS I can do this.使用
ui-router
和 AngularJS 上已弃用的component router
,我可以做到这一点。
Add a router-outlet
in ToolbarComponent
's template在
ToolbarComponent
的模板中添加一个router-outlet
And your route config will be like你的路线配置会像
const rootRoutes: Routes = [
{ path: '',
component: ToolbarComponent,
children: {
{ path: 'dashboard', component: DashboardComponent }
}
];
Now /dashboard
will render both Toolbar and Dashboard现在
/dashboard
将同时呈现 Toolbar 和 Dashboard
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.