应用程序服务
Kibana 已经迁移到单页应用程序。插件应该使用 Application service
API 来指示 Kibana 加载一个应用程序,并在 UI 中呈现以响应用户交互。该服务还提供实用程序来控制导航链接状态,无缝集成应用程序之间的路由,并按需加载异步块。
注意
应用程序服务仅在客户端可用。
import { AppMountParameters, CoreSetup, Plugin, DEFAULT_APP_CATEGORIES } from '@kbn/core/public';
export class MyPlugin implements Plugin {
public setup(core: CoreSetup) {
core.application.register({
category: DEFAULT_APP_CATEGORIES.kibana,
id: 'my-plugin',
title: 'my plugin title',
euiIconType: '/path/to/some.svg',
order: 100,
appRoute: '/app/my_plugin',
async mount(params: AppMountParameters) {
// Load application bundle
const { renderApp } = await import('./application');
// Get start services
const [coreStart, depsStart] = await core.getStartServices();
// Render the application
return renderApp(coreStart, depsStart, params);
},
});
}
}
- 请参考 application.register 接口
- 应用程序特定的 URL。
- 当用户导航到应用程序特定 URL 时,会调用
mount
回调。 core.getStartServices
方法提供在start
生命周期中可用的 API。mount
方法必须返回一个函数,该函数将被调用以卸载应用程序,当 Kibana 卸载应用程序时会调用该函数。您可以在此处放置清理逻辑。
注意
您可以自由使用任何 UI 库在 DOM 中呈现插件应用程序。 但是,我们建议您使用 React 和 EUI 用于所有基本 UI 组件,以创建一致的 UI 体验。