Implement Micro-application Lifecycles
masterIn icestark, micro-applications are frontend resources with a lifecycle consisting of two stages: mounting to the main application and unmounting from the main application.
There are two ways to declare these lifecycles:
1. Using mount/unmount (Recommended)
To ensure better compatibility with the single-spa ecosystem, it is recommended to export mount and unmount functions in UMD format (available in icestark 1.6.0+).
2. Using Global Registration
You can use registerAppEnter and registerAppLeave from @ice/stark-app to handle lifecycle events.
// Option 1: Recommended (UMD export)
import ReactDOM from 'react-dom';
import App from './App';
export function mount(props) {
ReactDOM.render(<App />, props.container);
}
export function unmount(props) {
ReactDOM.unmountComponentAtNode(props.container);
}
// Option 2: Global registration
import ReactDOM from 'react-dom';
import { registerAppEnter, registerAppLeave } from '@ice/stark-app';
import App from './App';
registerAppEnter((props) => {
ReactDOM.render(<App />, props.container);
});
registerAppLeave((props) => {
ReactDOM.unmountComponentAtNode(props.container);
});