Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using redux-micro-frontend for shared history #32

Open
peterkmurphy opened this issue Sep 28, 2021 · 2 comments
Open

Using redux-micro-frontend for shared history #32

peterkmurphy opened this issue Sep 28, 2021 · 2 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@peterkmurphy
Copy link

At the moment, my organisation is looking into the whole instance of microfrontends.

We have several applications (React + Redux + React Router) that we have developed - and are developing - separately. However, we are interested in having them integrated as microfrontends in another application (the 'container'), which would contain common functionality like the navigation bars. Otherwise, the microfrontends would generally do their own thing. Users can navigate to Microfrontend App 1 at address /mfeapp1, Microfrontend App 2 at address /mfeapp2, and so on. (If the applications are running as microfrontends, we can engineer it so that the different apps are running on different paths.)

Each app has Redux, but there is no shared state between the apps... with one exception: router history. And this is one area where it would be a good idea to have shared state, so that both the container and the microfrontends know what URL the user has navigated to.

What I am looking for is some guidance on whether redux-micro-frontend is suitable for this situation. In the container app, we have:

const reducers = (history: History<unknown>) => combineReducers({
  router: connectRouter(history), // From connected-react-router
});

And the container store is:

  store = createReduxStore(reducers(history), compose(
    applyMiddleware(
      thunk,
      routerMiddleware(history),
    ),
    /* eslint-disable-next-line no-underscore-dangle */
    process.env.NODE_ENV === 'development' && window.__REDUX_DEVTOOLS_EXTENSION__ ? window.__REDUX_DEVTOOLS_EXTENSION__() : (f: unknown) => f,
  ));

Microfrontends may be interacting with the history

import { push } from 'connected-react-router';
/* ... */
dispatch(push(path)); // The user has pressed a button.

I looked at your sample app, but I noticed that both the microfrontends are running on the same page. This seems a different situation from where my organisations finds itself.

@patrickCode patrickCode self-assigned this Sep 28, 2021
@patrickCode patrickCode added the documentation Improvements or additions to documentation label Sep 29, 2021
@patrickCode
Copy link
Contributor

From the description of your application, redux-micro-frontend can be used for maintaining the route history.
In fact, in our organization we are using this library for maintaining the route history. Similar to the architecture that you have mentioned here, we have multiple apps (in different pages and location), and the global routing history is maintained by this lib.

Let me know if you would wan't to know more about how we maintain the state history.

@peterkmurphy
Copy link
Author

@patrickCode That would be very much appreciated. Thank you/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants