如何将URL参数从孩子发送给父母

时间:2019-06-03 08:03:49

标签: angular angular-ui-router

我的应用进入外部URL进行代码输入,通过重定向uri返回,然后重定向到原始视图。 通过重定向uri重定向页面时,URL类似于:www.example.com/parent/child/:CODE。 然后,我将其重定向到www.example.com/parent。

是否可以通过状态转换将url参数(:CODE)发送给父对象?

我知道我可以为孩子定义组件,然后通过$ state.go向父组件添加参数:

this.$state.go('parent', {params: this.$state.params.PARAMS});

但是由于我不想仅为重定向创建额外的组件,所以我想知道是否有更好的方法? 我可以看到状态转换的参数(自动登录到控制台),但是在component中调用transition.from()不会返回任何内容。

Parent state declaration:
export const parentState: Ng2StateDeclaration = {
  name: 'parent',
  url: '/parent',
  views: {
    content: {component: ParentComponent}
  },
  params: {
   // How to get CODE param from child to here ??
  }
};

Child state declaration:
export const childState: Ng2StateDeclaration = {
  name: 'parent.child',
  url: '/child/:CODE',
  redirectTo: 'parent',
}

0 个答案:

没有答案