angular - Angular Routing:将动态 url 数据传递给组件
问题描述
我有以下路线:
const routes: Routes = [
{
path: ':product/new',
children: [{
path: 'std/:country',
component: SignUpComponent,
data: {
animation: 'animate',
segment: 'std',
country: ':country'
}
}, {
path: 'exp/:country',
component: PaymentComponent,
data: {
animation: 'animate',
segment: 'exp'
}
}
}
]
country: ':country'
将动态 url 数据传递给的正确方法是什么SignUpComponent
?如果是,我如何在我的 中使用这些数据SignUpComponent Component
?
解决方案
您不需要数据对象中的国家/地区属性。网址中的国家/地区信息应该足够了。
从路由中检索国家参数:
class SignUpComponent implements OnInit {
constructor(private activatedRoute: ActivatedRoute) {}
ngOnInit() {
this.activatedRoute.params.subscribe((params) => {
// params.country should be defined here
});
}
}
推荐阅读
- r - 从列表中提取值并添加到(面板)数据框
- karate - -Dkarate.config.dir 与 Windows 上的完整路径
- youtrack - 如何在 YouTrack 中将问题分配给 root
- c# - 为什么在填充我的自定义集合后,ICollection.Count 中有一个循环
- python - 在 python 正则表达式中使用 unicodes 列表
- python - 使用 urllib 在 python 中下载 pdf 文件会导致一些 html 垃圾
- wordpress - 向下滚动时 WP 管理栏和标题移动
- html - 在 div 中添加其他内容时,如何阻止 div 在 CSS Grid 布局中变大?
- docker - 在 Docker 中运行基于 Springboot 的应用程序
- python - Word2Vec:如何检查训练模型的向量值?