【发布时间】:2017-05-07 03:31:33
【问题描述】:
我需要将数据从一个组件传递到另一个组件,我发现只有在 url 中使用路由参数的方法:
所以我对路由器中的目标组件进行了这样的配置:
{
path: 'edit-tags/:type/:name/:id',
component: EditTagsComponent,
},
我从另一个组件中使用它:
this.router.navigate([`../edit-tags/${product.type}/${product.name}/${product.id}`], { relativeTo: this.route });
它工作正常,但我不想在 url 中显示id,还需要向组件传递更多数据。
我还看到在路由器中使用类似的配置:
{ path: 'test-product', component: ProductsContentComponent, data: { role: 'admin', type: 'test-product' } }
但我还没有找到在另一个组件中使用相同方法的示例。
那么,有没有办法在路由上将一些数据从一个组件传递到另一个组件,而不在 url 中反映呢?
【问题讨论】:
-
查看optional route parameters 和
NavigationExtras。不过,不确定您是否可以阻止数据显示在地址栏中。
标签: angular angular2-routing angular2-components