openmrs-esm-root-config is an in-browser javascript module that serves as the single-spa root config for OpenMRS. It is the very first javascript module that is loaded, and controls which other modules are loaded and active for any particular URL.
openmrs-esm-root-config is available on npm to be downloaded.
To accept all OpenMRS defaults for modules, do the following:
npm install --save @openmrs/esm-root-config
. Alternatively, go to get the files from jsdelivr.- Make the file
node_modules/@openmrs/esm-root-config/dist/openmrs-esm-root-config.defaults.js
available in your import map with the name@openmrs/esm-root-config
.
To customize which modules and single-spa applications are used, do the following:
- Create a new repo that will be your custom root config. For example, ampath-esm-root-config.
npm install --save @openmrs/esm-root-config
. Alternatively, go to get the files from jsdelivr.- Make your repo's bundle available in your import map, with the name
@openmrs/esm-root-config
. - In your repo's entry file, add the following code:
import { registerApplication, start } from 'single-spa'; import { registerAllCoreApplications } from '@openmrs/esm-root-config'; // Get all the core applications registerAllCoreApplications(); // or: registerAllCoreApplicationsExcept(['@openmrs/esm-login', '@openmrs/esm-devtools']) // Add your own application registerApplication( 'my-custom-app', () => System.import('my-custom-app'), location => location.pathname.startsWith('/custom') ) // start everything up start();
The following functions are exported from @openmrs/esm-root-config.
registerAllCoreApplications is a function that calls singleSpa.register() for each of the OpenMRS core applications.
None
None (undefined)
import { registerAllCoreApplications } from '@openmrs/esm-root-config';
registerAllCoreApplications();
registerAllCoreApplicationsExcept
allows you to specify an array of application
names that you do not want to be registered from the set of all OpenMRS core applications.
applicationNames
(required): an array of string names that must correspond with the OpenMRS core applications that you don't want registered.
None (undefined)
import { registerAllCoreApplicationsExcept } from '@openmrs/esm-root-config';
registerAllCoreApplicationsExcept(['@openmrs/esm-login', '@openmrs/esm-primary-navigation']);
routePrefix
is a utility function that helps you implement
single-spa activity functions.
The word "route" refers to the browser's url and the word "prefix" refers to a prefix in the
pathname.
prefix
(required): A string that starts with a/
character. Any time the browser's url's pathname starts with that url, your application will be active.location
(required): A Location object. You can just pass in the location given to your activity function.
A boolean that is true
when the location matches the prefix, and false
otherwise.
See code examples.
import { registerApplication } from 'single-spa';
import { routePrefix } from '@openmrs/esm-root-config';
registerApplication('my-custom-app', () => System.import('my-custom-app'), isCustomAppActive);
function isCustomAppActive(location) {
return routePrefix('/custom', location);
}
routeRegex
is a utility function that helps you implement
single-spa activity functions.
The word "route" refers to the browser's url and the word "prefix" refers to a prefix in the
pathname.
regex
(required). A regular expression that will be matched against the location's pathname.location
(required). A Location object. You can just pass in the location given to your activity function.
A boolean that is true
when the location matches the prefix, and false
otherwise.
import { registerApplication } from 'single-spa';
import { routeRegex } from '@openmrs-esm-root-config';
registerApplication('my-custom-app', () => System.import('my-custom-app'), isCustomAppActive);
function isCustomAppActive(location) {
return routeRegex(/^patient\/.+\/dashboard/, location);
}