This document outlines the features provided by the Luigi Client API. It covers these topics:
- Lifecycle - functions that define the lifecycle of different Luigi elements
- Callbacks - callback functions for initListener and customMessageListener
- Link manager - you can use the linkManager instead of an internal router
- Split view - allows you to open a micro frontend in the lower part of the content area in a "split screen" view
- uxManager - functions related to user interface
Use the functions and parameters to define the Lifecycle of listeners, navigation nodes, and Event data.
Registers a listener called with the context object and the Luigi Core domain as soon as Luigi is instantiated. Defer your application bootstrap if you depend on authentication data coming from Luigi.
initFn
Lifecycle~initListenerCallback the function that is called once Luigi is initialized, receives current context and origin as parameters
Removes an init listener.
id
string the id that was returned by theaddInitListener
function.
Registers a listener called with the context object when the URL is changed. For example, you can use this when changing environments in a context switcher in order for the micro frontend to do an API call to the environment picked.
contextUpdatedFn
function the listener function called each time Luigi context changes
Removes a context update listener.
id
string the id that was returned by theaddContextUpdateListener
function
Registers a listener called upon micro frontend inactivity. This happens when a new micro frontend gets shown while keeping the old one cached. Gets called when:
- navigating with preserveView
- navigating from or to a viewGroup
Does not get called when navigating normally, or when openAsModal
or openAsSplitView
are used.
inactiveFn
function the listener function called each time a micro frontend turns into an inactive state
Removes a listener for inactive micro frontends.
id
string the id that was returned by theaddInactiveListener
function
Registers a listener called when the micro frontend receives a custom message.
customMessageId
string the custom message idcustomMessageListener
Lifecycle~customMessageListenerCallback the function that is called when the micro frontend receives the corresponding event
Meta
- since: 0.6.2
Removes a custom message listener.
id
string the id that was returned by theaddInitListener
function
Meta
- since: 0.6.2
Returns the currently valid access token.
Returns string current access token
Returns the context object. Typically it is not required as the addContextUpdateListener() receives the same values.
Returns Object current context data
Returns the context object. It is an alias function for getEventData().
Returns Object current context data
Returns the node parameters of the active URL.
Node parameters are defined like URL query parameters but with a specific prefix allowing Luigi to pass them to the micro frontend view. The default prefix is ~ and you can use it in the following way: https://my.luigi.app/home/products?~sort=asc~page=3
.
NOTE: some special characters (
<
,>
,"
,'
,/
) in node parameters are HTML-encoded.
Returns Object node parameters, where the object property name is the node parameter name without the prefix, and its value is the value of the node parameter. For example {sort: 'asc', page: 3}
Returns the dynamic path parameters of the active URL. Path parameters are defined by navigation nodes with a dynamic pathSegment value starting with :, such as productId. All path parameters in the current navigation path (as defined by the active URL) are returned.
NOTE: some special characters (
<
,>
,"
,'
,/
) in path parameters are HTML-encoded.
Returns Object path parameters, where the object property name is the path parameter name without the prefix, and its value is the actual value of the path parameter. For example {productId: 1234, ...}
Returns the current client permissions as specified in the navigation node or an empty object. For details, see Node parameters.
Returns Object client permissions as specified in the navigation node
When the micro frontend is not embedded in the Luigi Core application and there is no init handshake you can set the target origin that is used in postMessage function calls by Luigi Client.
origin
string target origin
Meta
- since: 0.7.3
Sends a custom message to the Luigi Core application.
message
Object an object containing data to be sent to the Luigi Core to process it further. This object is set as an input parameter of the custom message listener on the Luigi Core sidemessage.id
string a string containing the message idmessage.MY_DATA_FIELD
any any other message data field
import LuigiClient from '@luigi-project/client';
LuigiClient.sendCustomMessage({id: 'environment.created', production: false})
Meta
- since: 0.6.2
Callback of the addInitListener
Type: Function
Callback of the customMessageListener
Type: Function
customMessage
Object custom message objectcustomMessage.id
string message idcustomMessage.MY_DATA_FIELD
any any other message data field
listenerId
string custom message listener id to be used for unsubscription
The Link Manager allows you to navigate to another route. Use it instead of an internal router to:
- Provide routing inside micro frontends.
- Reflect the route.
- Keep the navigation state in Luigi.
Disables the navigation handling for a single navigation request
It prevents Luigi Core from handling url change after navigate()
.
Used for auto-navigation
LuigiClient.linkManager().withoutSync().navigate('/projects/xy/foobar');
LuigiClient.linkManager().withoutSync().fromClosestContext().navigate('settings');
Meta
- since: 0.7.7
Navigates to the given path in the application hosted by Luigi. It contains either a full absolute path or a relative path without a leading slash that uses the active route as a base. This is the standard navigation.
path
string path to be navigated tosessionId
string current Luigi sessionIdpreserveView
boolean preserve a view by setting it totrue
. It keeps the current view opened in the background and opens the new route in a new frame. Use the goBack() function to navigate back. You can use this feature across different levels. Preserved views are discarded as soon as you use the standard navigate() function instead of goBack()modalSettings
Object opens a view in a modal. Use these settings to configure the modal's title and sizemodalSettings.title
string modal title. By default, it is the node label. If there is no label, it is left emptymodalSettings.size
("l"
|"m"
|"s"
) size of the modal (optional, default"l"
)
splitViewSettings
Object opens a view in a split view. Use these settings to configure the split view's behavioursplitViewSettings.title
string split view title. By default, it is the node label. If there is no label, it is left emptysplitViewSettings.size
number height of the split view in percent (optional, default40
)splitViewSettings.collapsed
boolean creates split view but leaves it closed initially (optional, defaultfalse
)
LuigiClient.linkManager().navigate('/overview')
LuigiClient.linkManager().navigate('users/groups/stakeholders')
LuigiClient.linkManager().navigate('/settings', null, true) // preserve view
Opens a view in a modal. You can specify the modal's title and size. If you don't specify the title, it is the node label. If there is no node label, the title remains empty. The default size of the modal is l
, which means 80%. You can also use m
(60%) and s
(40%) to set the modal size. Optionally, use it in combination with any of the navigation functions.
path
string navigation pathmodalSettings
Object? opens a view in a modal. Use these settings to configure the modal's title and size (optional, default{}
)modalSettings.title
string modal title. By default, it is the node label. If there is no label, it is left emptymodalSettings.size
("l"
|"m"
|"s"
) size of the modal (optional, default"l"
)
LuigiClient.linkManager().openAsModal('projects/pr1/users', {title:'Users', size:'m'});
- See: splitView for further documentation about the returned instance
Opens a view in a split view. You can specify the split view's title and size. If you don't specify the title, it is the node label. If there is no node label, the title remains empty. The default size of the split view is 40
, which means 40% height of the split view.
path
string navigation pathsplitViewSettings
Object opens a view in a split view. Use these settings to configure the split view's behaviour (optional, default{}
)splitViewSettings.title
string split view title. By default, it is the node label. If there is no label, it is left emptysplitViewSettings.size
number height of the split view in percent (optional, default40
)splitViewSettings.collapsed
boolean opens split view in collapsed state (optional, defaultfalse
)
const splitViewHandle = LuigiClient.linkManager().openAsSplitView('projects/pr1/logs', {title: 'Logs', size: 40, collapsed: true});
Returns Object instance of the SplitView. It provides Event listeners and you can use the available functions to control its behavior.
Meta
- since: 0.6.0
Sets the current navigation context to that of a specific parent node which has the navigationContext field declared in the navigation configuration. This navigation context is then used by the navigate
function.
navigationContext
string
LuigiClient.linkManager().fromContext('project').navigate('/settings')
Returns linkManager link manager instance
Sets the current navigation context which is then used by the navigate
function. This has to be a parent navigation context, it is not possible to use the child navigation contexts.
LuigiClient.linkManager().fromClosestContext().navigate('/users/groups/stakeholders')
Returns linkManager link manager instance
Sends node parameters to the route. The parameters are used by the navigate
function. Use it optionally in combination with any of the navigation functions and receive it as part of the context object in Luigi Client.
nodeParams
Object
LuigiClient.linkManager().withParams({foo: "bar"}).navigate("path")
// Can be chained with context setting functions such as:
LuigiClient.linkManager().fromContext("currentTeam").withParams({foo: "bar"}).navigate("path")
Returns linkManager link manager instance
Checks if the path you can navigate to exists in the main application. For example, you can use this helper method conditionally to display a DOM element like a button.
path
string path which existence you want to check
let pathExists;
LuigiClient
.linkManager()
.pathExists('projects/pr2')
.then(
(pathExists) => { }
);
Returns promise a promise which resolves to a Boolean variable specifying whether the path exists or not
Checks if there is one or more preserved views. You can use it to show a back button.
Returns boolean indicating if there is a preserved view you can return to
Discards the active view and navigates back to the last visited view. Works with preserved views, and also acts as the substitute of the browser back button. goBackContext is only available when using preserved views.
goBackValue
any data that is passed in the goBackContext field to the last visited view when using preserved views
LuigiClient.linkManager().goBack({ foo: 'bar' });
LuigiClient.linkManager().goBack(true);
Split view
Allows to open a micro frontend in a split screen in the lower part of the content area. Open it by calling const splitViewHandle = LuigiClient.linkManager().openAsSplitView
.
At a given time, you can open only one split view. It closes automatically when you navigate to a different route.
When you call handle.collapse()
, the split view gets destroyed. It recreates when you use handle.expand()
.
openAsSplitView
returns an instance of the split view handle. The functions, actions, and event handlers listed below allow you to control and manage the split view.
Meta
- since: 0.6.0
Collapses the split view
splitViewHandle.collapse();
Meta
- since: 0.6.0
Expands the split view
splitViewHandle.expand();
Meta
- since: 0.6.0
Closes and destroys the split view
splitViewHandle.close();
Meta
- since: 0.6.0
Sets the height of the split view
value
number lower height in percent
splitViewHandle.setSize(60);
Meta
- since: 0.6.0
Registers a listener for split view events
name
("expand"
|"collapse"
|"resize"
|"close"
) event namecallback
function gets called when this event gets triggered by Luigi
const listenerId = splitViewHandle.on('expand', () => {});
const listenerId = splitViewHandle.on('collapse', () => {});
const listenerId = splitViewHandle.on('resize', () => {});
const listenerId = splitViewHandle.on('close', () => {});
*
Returns string listener id
Meta
- since: 0.6.0
Unregisters a split view listener
id
string listener id
splitViewHandle.removeEventListener(listenerId);
Meta
- since: 0.6.0
Gets the split view status
splitViewHandle.exists();
Returns boolean true if a split view is loaded
Meta
- since: 0.6.0
Reads the size of the split view
splitViewHandle.getSize();
Returns number height in percent
Meta
- since: 0.6.0
Reads the collapse status
splitViewHandle.isCollapsed();
Returns boolean true if the split view is currently collapsed
Meta
- since: 0.6.0
Reads the expand status
splitViewHandle.isExpanded();
Returns boolean true if the split view is currently expanded
Meta
- since: 0.6.0
Use the UX Manager to manage the appearance features in Luigi.
Adds a backdrop with a loading indicator for the micro frontend frame. This overrides the loadingIndicator.enabled setting.
Removes the loading indicator. Use it after calling showLoadingIndicator() or to hide the indicator when you use the loadingIndicator.hideAutomatically: false node configuration.
Adds a backdrop to block the top and side navigation. It is based on the Fundamental UI Modal, which you can use in your micro frontend to achieve the same behavior.
Removes the backdrop.
This method informs the main application that there are unsaved changes in the current view in the iframe. For example, that can be a view with form fields which were edited but not submitted.
isDirty
boolean indicates if there are any unsaved changes on the current page or in the component
Shows a confirmation modal.
settings
Object the settings of the confirmation modal. If you don't provide any value for any of the fields, a default value is usedsettings.header
string the content of the modal header (optional, default"Confirmation"
)settings.body
string the content of the modal body (optional, default"Are you sure you want to do this?"
)settings.buttonConfirm
string the label for the modal confirm button (optional, default"Yes"
)settings.buttonDismiss
string the label for the modal dismiss button (optional, default"No"
)
import LuigiClient from '@luigi-project/client';
const settings = {
header: "Confirmation",
body: "Are you sure you want to do this?",
buttonConfirm: "Yes",
buttonDismiss: "No"
}
LuigiClient
.uxManager()
.showConfirmationModal(settings)
.then(() => {
// Logic to execute when the confirmation modal is dismissed
});
Returns promise which is resolved when accepting the confirmation modal and rejected when dismissing it
Shows an alert.
settings
Object the settings for the alertsettings.text
string the content of the alert. To add a link to the content, you have to set up the link in thelinks
object. The key(s) in thelinks
object must be used in the text to reference the links, wrapped in curly brackets with no spaces. If you don't specify any text, the alert is not displayedsettings.type
("info"
|"success"
|"warning"
|"error"
) sets the type of alertsettings.links
Object provides links datasettings.links.LINK_KEY
Object object containing the data for a particular link. To properly render the link in the alert message refer to the description of the settings.text parameter
settings.closeAfter
number (optional) time in milliseconds that tells Luigi when to close the Alert automatically. If not provided, the Alert will stay on until closed manually. It has to be greater than100
import LuigiClient from '@luigi-project/client';
const settings = {
text: "Ut enim ad minim veniam, {goToHome} quis nostrud exercitation ullamco {relativePath}. Duis aute irure dolor {goToOtherProject}",
type: 'info',
links: {
goToHome: { text: 'homepage', url: '/overview' },
goToOtherProject: { text: 'other project', url: '/projects/pr2' },
relativePath: { text: 'relative hide side nav', url: 'hideSideNav' }
},
closeAfter: 3000
}
LuigiClient
.uxManager()
.showAlert(settings)
.then(() => {
// Logic to execute when the alert is dismissed
});
Returns promise which is resolved when the alert is dismissed
Gets the current locale.
Returns string current locale
Sets current locale to the specified one.
NOTE: this must be explicitly allowed on the navigation node level by setting clientPermissions.changeCurrentLocale
to true
. (See Node parameters.)
locale
string locale to be set as the current locale
Checks if the current micro frontend is displayed inside a split view
Returns boolean indicating if it is loaded inside a split view
Meta
- since: 0.6.0
Checks if the current micro frontend is displayed inside a modal
Returns boolean indicating if it is loaded inside a modal
Meta
- since: 0.6.0
Callback of the addInitListener
Type: Function
Callback of the customMessageListener
Type: Function
customMessage
Object custom message objectcustomMessage.id
string message idcustomMessage.MY_DATA_FIELD
any any other message data field
listenerId
string custom message listener id to be used for unsubscription
The Link Manager allows you to navigate to another route. Use it instead of an internal router to:
- Provide routing inside micro frontends.
- Reflect the route.
- Keep the navigation state in Luigi.
Navigates to the given path in the application hosted by Luigi. It contains either a full absolute path or a relative path without a leading slash that uses the active route as a base. This is the standard navigation.
path
string path to be navigated tosessionId
string current Luigi sessionIdpreserveView
boolean preserve a view by setting it totrue
. It keeps the current view opened in the background and opens the new route in a new frame. Use the goBack() function to navigate back. You can use this feature across different levels. Preserved views are discarded as soon as you use the standard navigate() function instead of goBack()modalSettings
Object opens a view in a modal. Use these settings to configure the modal's title and sizemodalSettings.title
string modal title. By default, it is the node label. If there is no label, it is left emptymodalSettings.size
("l"
|"m"
|"s"
) size of the modal (optional, default"l"
)
splitViewSettings
Object opens a view in a split view. Use these settings to configure the split view's behavioursplitViewSettings.title
string split view title. By default, it is the node label. If there is no label, it is left emptysplitViewSettings.size
number height of the split view in percent (optional, default40
)splitViewSettings.collapsed
boolean creates split view but leaves it closed initially (optional, defaultfalse
)
LuigiClient.linkManager().navigate('/overview')
LuigiClient.linkManager().navigate('users/groups/stakeholders')
LuigiClient.linkManager().navigate('/settings', null, true) // preserve view
Opens a view in a modal. You can specify the modal's title and size. If you don't specify the title, it is the node label. If there is no node label, the title remains empty. The default size of the modal is l
, which means 80%. You can also use m
(60%) and s
(40%) to set the modal size. Optionally, use it in combination with any of the navigation functions.
path
string navigation pathmodalSettings
Object? opens a view in a modal. Use these settings to configure the modal's title and size (optional, default{}
)modalSettings.title
string modal title. By default, it is the node label. If there is no label, it is left emptymodalSettings.size
("l"
|"m"
|"s"
) size of the modal (optional, default"l"
)
LuigiClient.linkManager().openAsModal('projects/pr1/users', {title:'Users', size:'m'});
- See: splitView for further documentation about the returned instance
Opens a view in a split view. You can specify the split view's title and size. If you don't specify the title, it is the node label. If there is no node label, the title remains empty. The default size of the split view is 40
, which means 40% height of the split view.
path
string navigation pathsplitViewSettings
Object opens a view in a split view. Use these settings to configure the split view's behaviour (optional, default{}
)splitViewSettings.title
string split view title. By default, it is the node label. If there is no label, it is left emptysplitViewSettings.size
number height of the split view in percent (optional, default40
)splitViewSettings.collapsed
boolean opens split view in collapsed state (optional, defaultfalse
)
const splitViewHandle = LuigiClient.linkManager().openAsSplitView('projects/pr1/logs', {title: 'Logs', size: 40, collapsed: true});
Returns Object instance of the SplitView. It provides Event listeners and you can use the available functions to control its behavior.
Meta
- since: 0.6.0
Sets the current navigation context to that of a specific parent node which has the navigationContext field declared in the navigation configuration. This navigation context is then used by the navigate
function.
navigationContext
string
LuigiClient.linkManager().fromContext('project').navigate('/settings')
Returns linkManager link manager instance
Sets the current navigation context which is then used by the navigate
function. This has to be a parent navigation context, it is not possible to use the child navigation contexts.
LuigiClient.linkManager().fromClosestContext().navigate('/users/groups/stakeholders')
Returns linkManager link manager instance
Sends node parameters to the route. The parameters are used by the navigate
function. Use it optionally in combination with any of the navigation functions and receive it as part of the context object in Luigi Client.
nodeParams
Object
LuigiClient.linkManager().withParams({foo: "bar"}).navigate("path")
// Can be chained with context setting functions such as:
LuigiClient.linkManager().fromContext("currentTeam").withParams({foo: "bar"}).navigate("path")
Returns linkManager link manager instance
Checks if the path you can navigate to exists in the main application. For example, you can use this helper method conditionally to display a DOM element like a button.
path
string path which existence you want to check
let pathExists;
LuigiClient
.linkManager()
.pathExists('projects/pr2')
.then(
(pathExists) => { }
);
Returns promise a promise which resolves to a Boolean variable specifying whether the path exists or not
Checks if there is one or more preserved views. You can use it to show a back button.
Returns boolean indicating if there is a preserved view you can return to
Discards the active view and navigates back to the last visited view. Works with preserved views, and also acts as the substitute of the browser back button. goBackContext is only available when using preserved views.
goBackValue
any data that is passed in the goBackContext field to the last visited view when using preserved views
LuigiClient.linkManager().goBack({ foo: 'bar' });
LuigiClient.linkManager().goBack(true);
Split view
Allows to open a micro frontend in a split screen in the lower part of the content area. Open it by calling const splitViewHandle = LuigiClient.linkManager().openAsSplitView
.
At a given time, you can open only one split view. It closes automatically when you navigate to a different route.
When you call handle.collapse()
, the split view gets destroyed. It recreates when you use handle.expand()
.
openAsSplitView
returns an instance of the split view handle. The functions, actions, and event handlers listed below allow you to control and manage the split view.
Meta
- since: 0.6.0
Collapses the split view
splitViewHandle.collapse();
Meta
- since: 0.6.0
Expands the split view
splitViewHandle.expand();
Meta
- since: 0.6.0
Closes and destroys the split view
splitViewHandle.close();
Meta
- since: 0.6.0
Sets the height of the split view
value
number lower height in percent
splitViewHandle.setSize(60);
Meta
- since: 0.6.0
Registers a listener for split view events
name
("expand"
|"collapse"
|"resize"
|"close"
) event namecallback
function gets called when this event gets triggered by Luigi
const listenerId = splitViewHandle.on('expand', () => {});
const listenerId = splitViewHandle.on('collapse', () => {});
const listenerId = splitViewHandle.on('resize', () => {});
const listenerId = splitViewHandle.on('close', () => {});
*
Returns string listener id
Meta
- since: 0.6.0
Unregisters a split view listener
id
string listener id
splitViewHandle.removeEventListener(listenerId);
Meta
- since: 0.6.0
Gets the split view status
splitViewHandle.exists();
Returns boolean true if a split view is loaded
Meta
- since: 0.6.0
Reads the size of the split view
splitViewHandle.getSize();
Returns number height in percent
Meta
- since: 0.6.0
Reads the collapse status
splitViewHandle.isCollapsed();
Returns boolean true if the split view is currently collapsed
Meta
- since: 0.6.0
Reads the expand status
splitViewHandle.isExpanded();
Returns boolean true if the split view is currently expanded
Meta
- since: 0.6.0
Use the UX Manager to manage the appearance features in Luigi.
Adds a backdrop with a loading indicator for the micro frontend frame. This overrides the loadingIndicator.enabled setting.
Removes the loading indicator. Use it after calling showLoadingIndicator() or to hide the indicator when you use the loadingIndicator.hideAutomatically: false node configuration.
Adds a backdrop to block the top and side navigation. It is based on the Fundamental UI Modal, which you can use in your micro frontend to achieve the same behavior.
Removes the backdrop.
This method informs the main application that there are unsaved changes in the current view in the iframe. For example, that can be a view with form fields which were edited but not submitted.
isDirty
boolean indicates if there are any unsaved changes on the current page or in the component
Shows a confirmation modal.
settings
Object the settings of the confirmation modal. If you don't provide any value for any of the fields, a default value is usedsettings.header
string the content of the modal header (optional, default"Confirmation"
)settings.body
string the content of the modal body (optional, default"Are you sure you want to do this?"
)settings.buttonConfirm
string the label for the modal confirm button (optional, default"Yes"
)settings.buttonDismiss
string the label for the modal dismiss button (optional, default"No"
)
import LuigiClient from '@luigi-project/client';
const settings = {
header: "Confirmation",
body: "Are you sure you want to do this?",
buttonConfirm: "Yes",
buttonDismiss: "No"
}
LuigiClient
.uxManager()
.showConfirmationModal(settings)
.then(() => {
// Logic to execute when the confirmation modal is dismissed
});
Returns promise which is resolved when accepting the confirmation modal and rejected when dismissing it
Shows an alert.
settings
Object the settings for the alertsettings.text
string the content of the alert. To add a link to the content, you have to set up the link in thelinks
object. The key(s) in thelinks
object must be used in the text to reference the links, wrapped in curly brackets with no spaces. If you don't specify any text, the alert is not displayedsettings.type
("info"
|"success"
|"warning"
|"error"
) sets the type of alertsettings.links
Object provides links datasettings.links.LINK_KEY
Object object containing the data for a particular link. To properly render the link in the alert message refer to the description of the settings.text parameter
settings.closeAfter
number (optional) time in milliseconds that tells Luigi when to close the Alert automatically. If not provided, the Alert will stay on until closed manually. It has to be greater than100
import LuigiClient from '@luigi-project/client';
const settings = {
text: "Ut enim ad minim veniam, {goToHome} quis nostrud exercitation ullamco {relativePath}. Duis aute irure dolor {goToOtherProject}",
type: 'info',
links: {
goToHome: { text: 'homepage', url: '/overview' },
goToOtherProject: { text: 'other project', url: '/projects/pr2' },
relativePath: { text: 'relative hide side nav', url: 'hideSideNav' }
},
closeAfter: 3000
}
LuigiClient
.uxManager()
.showAlert(settings)
.then(() => {
// Logic to execute when the alert is dismissed
});
Returns promise which is resolved when the alert is dismissed
Gets the current locale.
Returns string current locale
Sets current locale to the specified one.
NOTE: this must be explicitly allowed on the navigation node level by setting clientPermissions.changeCurrentLocale
to true
. (See Node parameters.)
locale
string locale to be set as the current locale
Checks if the current micro frontend is displayed inside a split view
Returns boolean indicating if it is loaded inside a split view
Meta
- since: 0.6.0
Checks if the current micro frontend is displayed inside a modal
Returns boolean indicating if it is loaded inside a modal
Meta
- since: 0.6.0