title: "MainDashboardButton" post_status: publish comment_status: open taxonomy: category: - gutenberg-docs post_tag: - Slotfills - Reference Guides - Repos


MainDashboardButton

此插槽允许替换文章编辑器中的默认主仪表盘按钮。自 WordPress 6.2 起,站点编辑器中不再提供此功能。 它用于在全屏编辑模式下返回主 wp-admin 仪表盘。

请注意,此 SlotFill 仍被视为实验性功能,可能会发生变化

示例

更改图标

这将把标题栏中的 W 图标按钮替换为关闭图标。

import { registerPlugin } from '@wordpress/plugins';
import { __experimentalMainDashboardButton as MainDashboardButton } from '@wordpress/edit-post';
import { close } from '@wordpress/icons';

const MainDashboardButtonTest = () => (
    <MainDashboardButton>
        <FullscreenModeClose icon={ close } />
    </MainDashboardButton>
);

registerPlugin( 'main-dashboard-button-test', {
    render: MainDashboardButtonTest,
} );

全屏模式下的文章编辑界面,显示关闭图标而非默认的 W 图标

更改图标和链接

此示例将标题栏中的图标更改为外部链接图标,点击后将跳转至 https://wordpress.org。

import { registerPlugin } from '@wordpress/plugins';
import {
    __experimentalFullscreenModeClose as FullscreenModeClose,
    __experimentalMainDashboardButton as MainDashboardButton,
} from '@wordpress/edit-post';
import { external } from '@wordpress/icons';

const MainDashboardButtonIconTest = () => (
    <MainDashboardButton>
        <FullscreenModeClose icon={ external } href="https://wordpress.org" />
    </MainDashboardButton>
);

registerPlugin( 'main-dashboard-button-icon-test', {
    render: MainDashboardButtonIconTest,
} );

全屏模式下的文章编辑界面,显示外部链接图标而非默认的 W 图标