Version: 5.x
single-spa-preact
single-spa-preact is a helper library that helps implement single-spa registered application lifecycle functions (bootstrap, mount and unmount) for for use with Preact. Check out the single-spa-preact github.
npm install --save preact
In your project’s entry file, add the following:
import preact from 'preact';
import rootComponent from './path-to-root-component.js';
import singleSpaPreact from 'single-spa-preact';
const preactLifecycles = singleSpaPreact({
preact,
rootComponent,
domElementGetter: () => document.getElementById('main-content'),
});
export const bootstrap = preactLifecycles.bootstrap;
export const mount = preactLifecycles.mount;
export const unmount = preactLifecycles.unmount;
All options are passed to single-spa-preact via the opts
parameter when calling singleSpaPreact(opts)
. The following options are available:
preact
: (required) The main Preact object, which is generally either exposed onto the window or is available viarequire('preact')
orimport preact from 'preact'
.rootComponent
: (required) The top level preact component which will be rendereddomElementGetter
: (optional) A function that is given the single-spa props and returns a DOMElement. This dom element is where the Preact application will be bootstrapped, mounted, and unmounted. If omitted, a div will be created and appended to the body.
当前内容版权归 single-spa 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 single-spa .