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

fix: make Tutor-MFE config compatible with React Router v6 #574

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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