是否可以通过路由器发送复杂的对象?
这是我正在做和尝试做的事情:
在搜索页面中,用户可以单击结果之一上的按钮,该按钮将调用导致该行触发的方法。this.router.navigate(['profile-detail', selection]);
The selection
对象在导航之前看起来像这样。
{
profile: {
id: number,
fname: string,
lname: string
},
contact: {
type: string,
address: string
},
books: [{
title: string,
author: string
}]
}
然而,当我们进入个人资料详细信息页面时,this.route.snapshot.params
将此作为实际数据:
{
profile: "[object Object]",
contact: "[object Object]",
books: "[object Object]"
}
不可以,路由器需要将数据序列化到浏览器的URL栏,而URL栏只支持字符串。
您可以使用共享服务在不是父/子或兄弟的组件之间传递对象,也可以像路由器一样动态添加。
也可以看看https://angular.io/docs/ts/latest/cookbook/component-communication.html#!#bidirection-service https://angular.io/docs/ts/latest/cookbook/component-communication.html#!#bidirectional-service
根据您的具体要求,解析器也可能起作用https://angular.io/docs/ts/latest/guide/router.html#!#resolve-guard https://angular.io/docs/ts/latest/guide/router.html#!#resolve-guard
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)