I'm start using Micro Frontend with Module Federation Plugin . Now i faced with some issues on building routing between my applications. My Host application have route 3 mfe apps. Each of them have own routing inside. Navigation in Host-app is working, as inner navigation, but when i clicked again nav to hostApp/app1 when I on hostApp/app1/somePage1 it still render hostApp/app1/somePage1. What architecture you can recommend? How i can control it?Now I use react-router-dom V6 but i want to build application in way that tomorrow i can add another library like angular-router or bla-bla-bla-Router without any changes in host
export default function HostApp() {
return (
<BrowserRouter>
<div>Hello, I'm the host app!</div>
<NavLink to='/app1'> <button> app1 </button> </NavLink>
<NavLink to='/app2'> <button> app1 </button> </NavLink>
<NavLink to='/app3'> <button> app1 </button> </NavLink>
<Routes>
<Route path='/' element={
<Suspense fallback={'Loading'}><div>home page container</div></Suspense>} />
<Route path='app1/*' element={
<Suspense fallback={'Loading'}> <MfeApp1/></Suspense>}/>
<Route path='app2/*' element={
<Suspense fallback={'Loading'}> <MfeApp2/></Suspense>}/>
<Route path='app3/*' element={
<Suspense fallback={'Loading'}> <MfeApp3/></Suspense>}/>
</Routes>
</BrowserRouter>
)}
MfeApp:
export default function MfeApp1() {
return (
<BrowserRouter>
<h1>It is a Mfe App1 </h1>
<Routes>
<Route index path='app1' element={<HomePageApp1 />} />
<Route path='app1/somePAge' element={<SomePageOfMfeApp1 />} />
</Routes>
</>
)
}
Is it a good idea to use in both application BrowserRouter? I see a big issue here when 2 application try to control browser history. But if i leave onle one BrouserRouter in Host App i get error:"useRoutes() may be used only in the context of a component". That's also makes sense for me because inner app also need some Router to control it. I also tried to use MemoryBrowser and memory history in mfe apps and control path with callbacks like onNavigete(fromHost) and onParentNavigate(from mfe) but I failed to do it with react-router-dom V6. So any examples of working code or your advises will be so helpfull