我有一个OAuth进程弹出一个窗口,但是当我登录时,重定向到OAuth回调页面发生在弹出窗口而不是父窗口(window.opener).这可能有点hacky,但我想让弹出窗口告诉父母“我们被授权!”.
这实际上有效:
OAuthCallback = React.createClass({ displayName: 'OAuthCallback',render() { window.opener.console.log('hello parent window'); return ( <div> Hi,OAuth is process is done. </div> ) } });
但是我想知道是否有某些方法可以让弹出窗口告诉父窗口调用prop函数,例如this.props.oauthSucceeded().
当您无法在组件之间建立任何父子关系或兄弟关系时,React建议您设置一个事件系统.
原文链接:https://www.f2er.com/react/300794.htmlFor communication between two components that don’t have a
parent-child relationship,you can set up your own global event
system. Subscribe to events in componentDidMount(),unsubscribe in
componentWillUnmount(),and call setState() when you receive an event.
Flux pattern is one of the possible ways to arrange this.
见https://facebook.github.io/react/tips/communicate-between-components.html
浏览window.postMessage进行跨窗口通信(https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage)