Last active
June 27, 2020 08:11
-
-
Save EyalPerry/81627975b72abe71edf6bbd3804e8bda to your computer and use it in GitHub Desktop.
microfrontend
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
import React {useState, useEffect} from 'react'; | |
import {Switch, Route} from 'react-router-dom'; | |
function Frontend({manifest}){ | |
return <iframe src={manifest.url} /> | |
} | |
function App() { | |
const [manifest, setManifest] = useState(); | |
useEffect(() => { | |
fetch('https://localhost/my-project/manifest').then(r=>r.json()).then(setManifest) | |
},[]); | |
if(!manifest){ | |
return <div>Loading</div> | |
} | |
return ( | |
<Switch> | |
{manifest.apps.map(app => <Route to={app.route}><Frontend manifest={app}/></Route>)} | |
</Switch> | |
) | |
} | |
export default App; |
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
{ | |
"apps":[ | |
{ | |
"id":"user-profile", | |
"url": "http://localhost:3000/index.js", | |
"route":"/profile" | |
}, | |
{ | |
"id":"shop", | |
"url": "http://localhost:3001/index.js", | |
"route":"/ship" | |
} | |
] | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment