@akinon/app-shell
v1.6.0
Published
Akinon AppShell library. This library is used to create a new app shell(where akinon plugins can work inside) for Akinon projects.
Downloads
2,202
Readme
Akinon App Shell Library
The app-shell library is designed to orchestrate the integration of micro-frontend applications, providing a unified shell for navigation, theming, and inter-app communication.
Installation
To incorporate the app-shell library into your main application, execute:
pnpm install @akinon/app-shellUsage
Incorporate the AppShellProvider at the top level of your main application:
import React from 'react';
import ReactDOM from 'react-dom';
import { AppShellProvider } from '@akinon/app-shell';
import MainApp from './MainApp';
ReactDOM.render(
<AppShellProvider apps={yourAppsConfig} navigation={yourNavigationHandler}>
<MainApp />
</AppShellProvider>,
document.getElementById('main')
);yourAppsConfig should be an array of app configurations, including IDs, URLs, and types.
API
AppShellProvider
Props:
apps: An array of application configurations.navigation: Navigation handler for the shell.data: Optional shared data for micro-frontends. The shell addsshellBaseUrlto the copy each app receives; seeresolveUrlbelow.
navigation
interface ShellNavigation {
navigate: (payload: ShellNavigationPayload) => void;
resolveUrl?: (payload: ShellNavigationPayload) => string | undefined;
}navigatereceives{ id, path, external, newTab }. WhennewTabis true the host opens the new browser tab itself: the shell forwards the flag and never callswindow.open, because only the host knows its own url grammar. Build the destination with the same helper the same-tab branch uses, so the two cannot drift apart. Anexternalpath arrives from the iframe untouched, so open it only when it is anhttp:orhttps:url: ajavascript:ordata:url handed towindow.openruns in the shell's context, and the shell does not filter it.- Neither callback is captured when an app's iframe is set up: the shell reads both off the
navigationobject of your latest render, so a handler rebuilt around render-scoped values (the active language, the active channel) is the one that runs on the next call. resolveUrlis optional. It answers "what url would you navigate to for this payload" without navigating, and the shell broadcasts the answer to the app asdata.shellBaseUrl; clients join their own paths onto it to render real<a href target="_blank">links. The shell calls it on everySET_DATAemit — once per app when its iframe hands over its config, once per rich-modal iframe, and again for every app whenever the shell'sdataprop changes — always with an emptypath, so the returned url carries the host url grammar only. Theidit receives is the id of the app that owns the bus; a rich modal is resolved with its parent app's id, because its own uuid is not an app the host has registered.resolveUrlshould return an absolute url. The shell drops any query string and hash from it before it is broadcast — the client appends the app path to it as plain text, so either would swallow the path. A relative url is resolved against the shell's own origin. Returningundefinedor an empty string, throwing, or not implementingresolveUrlat all leavesshellBaseUrlout of the data the app receives: the shell never substitutes the page origin, since a url built from the wrong origin is exactly the failure this callback exists to prevent.
Configuration
Define each micro-frontend application with:
id: Unique identifier.url: Source URL for the iframe.type: Type of app, e.g., 'full_page' or 'plugin'.
Extending
The app shell is designed to be extendable. Implement custom logic for navigation, theming, and more to fit the needs of your micro-frontend architecture.
For detailed documentation on extending the app shell, configuration options, and more advanced use cases, refer to the full documentation.
