diff --git a/src/initialize.js b/src/initialize.js index 36527b8eb..2c7223595 100644 --- a/src/initialize.js +++ b/src/initialize.js @@ -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` diff --git a/src/react/AppProvider.jsx b/src/react/AppProvider.jsx index 4743fdfa0..a2ccd8bb1 100644 --- a/src/react/AppProvider.jsx +++ b/src/react/AppProvider.jsx @@ -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/ @@ -72,7 +73,7 @@ export default function AppProvider({ store, children, wrapWithRouter }) { > {wrapWithRouter ? ( - + {children} ) : children}