Skip to content

Instantly share code, notes, and snippets.

@bensampaio
Last active January 7, 2020 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bensampaio/2a23ec06243f5a327fc7e7b1ed99e8e1 to your computer and use it in GitHub Desktop.
Save bensampaio/2a23ec06243f5a327fc7e7b1ed99e8e1 to your computer and use it in GitHub Desktop.
Example of a basic IFrame component and respective configuration with react-router
<BrowserRouter>
<Route component={IFrame} path={['/messages', '/messages/thread/new', '/messages/thread/:id']} />
</BrowserRouter>
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