Last active
January 7, 2020 12:21
-
-
Save bensampaio/2a23ec06243f5a327fc7e7b1ed99e8e1 to your computer and use it in GitHub Desktop.
Example of a basic IFrame component and respective configuration with react-router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<BrowserRouter> | |
<Route component={IFrame} path={['/messages', '/messages/thread/new', '/messages/thread/:id']} /> | |
</BrowserRouter> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class IFrame extends PureComponent { | |
constructor(props) { | |
super(props); | |
this.iframeElement = React.createRef(); | |
this.handleLoad = this.handleLoad.bind(this); | |
} | |
handleLoad() { | |
// ... | |
} | |
render() { | |
const { location } = this.props; | |
const url = '/_content' + location.pathname + location.search + location.hash; | |
return <iframe ref={this.iframeElement} src={url} onLoad={this.handleLoad} />; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment