Skip to content

Instantly share code, notes, and snippets.

@TheMcMurder
Created August 4, 2020 19:47
Show Gist options
  • Save TheMcMurder/f3d15f646d4b29bd6dbd7ea772de1217 to your computer and use it in GitHub Desktop.
Save TheMcMurder/f3d15f646d4b29bd6dbd7ea772de1217 to your computer and use it in GitHub Desktop.
import React, { useEffect, useRef } from "react";
// import { BrowserRouter, Route, Switch, Redirect } from "react-router-dom";
// import PeoplePage from "./people-page/people-page.component.js";
export default function Root(props) {
const iframeRef = useRef()
useEffect(() => {
setTimeout(() => {
iframeRef.current.contentWindow.postMessage(
{ source: 'quicksilver', pathname: window.location.pathname.replace('/people/', '') },
'http://localhost:4200'
);
}, 1000)
}, [])
useEffect(() => {
function listen (event) {
if (event.origin.includes('localhost:4200')) {
console.log('change url to', event.data.pathname)
}
}
window.addEventListener('message', listen)
return () => window.removeEventListener('message', listen)
}, [])
return (
<iframe
ref={iframeRef}
className='h-screen'
id='angular-iframe-tour'
src='http://localhost:4200'
width='100%'
/>
// <BrowserRouter>
// <Route path="/people/:personId" component={PeoplePage} />
// <Route path="/people" component={PeoplePage} exact />
// </BrowserRouter>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment