目前我正在为我的应用使用此路由设置:
{ path: ':group',component: ArticleListComponent,children: [{ path: ':subgroup',children: [{ path: ':chapter',children: [{ path: ':section',children: [ ] } ] } ] } ] },
我使用相同的组件来列出文章,因为模板和代码不会改变,但我想使用url来过滤这些文章.应用程序应该使用路由参数而不是获取参数.有了这些参数,我想调用一个API来获取属于这个url的文章:/ group1 / subgroup1 / chapter1 / section1.
const params = this.route.snapshot.params; // {group: "group1"} const params = this.route.parent.snapshot.params; // {} const params = this.route.firstChild.snapshot.params; // {group: "group1",subgroup: "subgroup1"}
我怎么能一次得到所有这些参数?