question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple browser routers

See original GitHub issue

Hello,

The approach which I saw in examples is where we share our routes through module federation and shell application handles the routing for all the apps.

But what if I only share a single component which has it’s own internal routing mechanism, and I don’t need to expose anything else. Is that possible. I tried by passing basename.

Routes work for remote application when run in standalone, but when it’s integrated to shell they don’t work.

for example: Shell application

<BrowserRouter>
 <Route path="/app/*">
          <RemoteAppl basename="app"/>
        </Route>
</BrowserRouter>

Remote Application

<BrowserRouter  history={history} basename={props.basename}>
 <div style={{width: '100%', marginTop: 10, padding: 10, border: '5px solid gray', height: '100%' }}>
          <ul style={{ display: 'flex', margin: 20 }}>
            <li>
              <Link to="/experience-1">Internal Link 1</Link>
            </li>

            <li style={{ marginLeft: 20 }}>
              <Link to="/experience-2">Internal Link 2</Link>
            </li>
          </ul>
          <Route path="/experience-1">
            <ShoppingList />
          </Route>
      </div>
</BrowserRouter>

I saw this thread, but couldn’t make anything out of it https://github.com/module-federation/module-federation-examples/issues/536

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
XiaofengXie16commented, Jun 1, 2022

Hi @adarsh0d

This example is probably what you are looking for: https://github.com/XiaofengXie16/module-federation-nested-react-router-v6

This approach will work with react-router v5 as well (In my company, I am using v5).

However, there is one caveat, if you want to do inter-app navigation, you will need to pass the navigation function (useNavigation for V6) from the app shell down to the clients.

0reactions
ScriptedAlchemycommented, Aug 29, 2022

Send pr if it would make a good example

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to have multiple BrowserRouter in react app
Nope. It is not possible. You can have only one BrowserRouter. Nest the rest inside. – Farman Ali. Apr 20, 2021 at 9:33....
Read more >
Example - multiple-routers - Reach Router
Multiple Routers · Embedded Routers · Animation. Tutorial. Introduction · Installation · Link · Router · URL Parameters ... Primary API. Router.
Read more >
Ultimate React Router v6 Guide
React Router is by far the most popular routing library in React and ... Dynamic Routing; Routing Priority; Nested Routes; Multiple Routes ...
Read more >
ReactJS | Types of Routers - GeeksforGeeks
Browser Router ; Hash Router. Pre-requisite: Before start this article you need to have basic knowledge of React Router. Memory Router: Memory ...
Read more >
Handling multiple pages with the external component React ...
The Router simulates multiple pages with a little trick of changing the browser URL using JavaScript. It is like typing google.com and then ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found