Skip to content

Commit

Permalink
fix: make PUBLIC_PATH compatible with React Router v6 (#574)
Browse files Browse the repository at this point in the history
  • Loading branch information
ormsbee authored Oct 3, 2023
1 parent 8182d21 commit 562497f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ export const history = (typeof window !== 'undefined')
basename: getPath(getConfig().PUBLIC_PATH),
}) : createMemoryHistory();

/**
* The string basename that is the root directory of this MFE.
*
* In devstack, this should always just return "/", because each MFE is in its own server/domain.
*
* In Tutor, all MFEs are deployed to a common server, each under a different top-level directory.
* The basename is the root path for a given MFE, e.g. "/library-authoring". It is set by tutor-mfe
* as an ENV variable in the Docker file, and we read it here from that configuration so that it
* can be passed into a Router later.
*/
export const basename = getPath(getConfig().PUBLIC_PATH);

/**
* The default handler for the initialization lifecycle's `initError` phase. Logs the error to the
* LoggingService using `logError`
Expand Down
3 changes: 2 additions & 1 deletion src/react/AppProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
IntlProvider,
LOCALE_CHANGED,
} from '../i18n';
import { basename } from '../initialize';

/**
* A wrapper component for React-based micro-frontends to initialize a number of common data/
Expand Down Expand Up @@ -72,7 +73,7 @@ export default function AppProvider({ store, children, wrapWithRouter }) {
>
<OptionalReduxProvider store={store}>
{wrapWithRouter ? (
<Router>
<Router basename={basename}>
{children}
</Router>
) : children}
Expand Down

0 comments on commit 562497f

Please sign in to comment.