Skip to content

Commit 562497f

Browse files
authored
fix: make PUBLIC_PATH compatible with React Router v6 (#574)
1 parent 8182d21 commit 562497f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/initialize.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,18 @@ export const history = (typeof window !== 'undefined')
102102
basename: getPath(getConfig().PUBLIC_PATH),
103103
}) : createMemoryHistory();
104104

105+
/**
106+
* The string basename that is the root directory of this MFE.
107+
*
108+
* In devstack, this should always just return "/", because each MFE is in its own server/domain.
109+
*
110+
* In Tutor, all MFEs are deployed to a common server, each under a different top-level directory.
111+
* The basename is the root path for a given MFE, e.g. "/library-authoring". It is set by tutor-mfe
112+
* as an ENV variable in the Docker file, and we read it here from that configuration so that it
113+
* can be passed into a Router later.
114+
*/
115+
export const basename = getPath(getConfig().PUBLIC_PATH);
116+
105117
/**
106118
* The default handler for the initialization lifecycle's `initError` phase. Logs the error to the
107119
* LoggingService using `logError`

src/react/AppProvider.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
IntlProvider,
1717
LOCALE_CHANGED,
1818
} from '../i18n';
19+
import { basename } from '../initialize';
1920

2021
/**
2122
* A wrapper component for React-based micro-frontends to initialize a number of common data/
@@ -72,7 +73,7 @@ export default function AppProvider({ store, children, wrapWithRouter }) {
7273
>
7374
<OptionalReduxProvider store={store}>
7475
{wrapWithRouter ? (
75-
<Router>
76+
<Router basename={basename}>
7677
{children}
7778
</Router>
7879
) : children}

0 commit comments

Comments
 (0)