پیکربندی ناوبری

ما ساختار ناوبری خود را به عنوان آرایه ای از اشیاء تشکیل می دهیم و در نهایت آن را به UI تبدیل می کنیم. شما می توانید به راحتی ساختار ناوبری برنامه را با دسترسی به src/configs/navigation.config/index.tsتغییر دهید یا سفارشی سازی کنید

اینجا نوع یک آیتم منو را مشاهده می کنید

export type HorizontalMenuMeta = {
    layout: 'default'
} | {
    layout: 'columns'
    showColumnTitle?: boolean
    columns: 1 | 2 | 3 | 4 | 5
} | {
    layout: 'tabs'
    columns: 1 | 2 | 3 | 4 | 5
}

export interface NavigationTree {
    key: string
    path: string
    isExternalLink?: boolean
    title: string
    translateKey: string
    icon: string
    type: 'title' | 'collapse' | 'item'
    authority: string[]
    subMenu: NavigationTree[]
    description?: string
    meta?: {
        horizontalMenu?: HorizontalMenuMeta
        description?: {
            translateKey: string
            label: string
        }
    }
}

propertiesتوضیحاتنوعپیش‌فرض
keyAn key that match with the route for highlighting purposestring-
pathAn URL that this menu item link tostring-
isExternalLinkWhether to open link in new tab upon clickboolean-
titleRendered text of this menu itemstring-
translateKeyTranslate key to translate the rendered text in menu item, fallback to title if empty or invalidstring-
iconRender icon in menu item, string value must tally with object key in navigation-icon.config.tsxstring-
typeTo define the type of current menu item'title' | 'collapse' | 'item'-
authorityDisplay menu items to users who have the roles given, there will be no access block if the this field is undefine or empty arraystring[]-
subMenuWhether have child in this menu item, it will render a menu group under this menu item, if the type is 'title' or 'collapse', this field accept properties within this tablenavigationConfig[]-
metaThis is an optional configuration field for navigation. It can include additional information that's only needed in specific use cases{ horizontalMenu?: HorizontalMenuMeta description?: { translateKey: string label: string } }-
meta.horizontalMenuFurther configuration for horizontal menu, e.g layout, columns & etc.{ layout: 'default' } | { layout: 'columns' showColumnTitle?: boolean columns: 1 | 2 | 3 | 4 | 5 } | { layout: 'tabs' columns: 1 | 2 | 3 | 4 | 5 }-
meta.descriptionDescription of the page, description only available when themeConfig.layout.type is 'contentOverlay'navigationConfig[]-

یک مثال از تنظیمات ساختار یافته ناوبری

const navigationConfig = [
    {
        key: 'uiComponent',
        path: '',
        title: 'Ui Component',
        translateKey: 'nav.uiComponents',
        icon: 'uiComponents',
        type: 'title',
        authority: ['admin', 'user'],
        /** We can define mnu config here, if we are using horizontal menu */
        meta: {
            horizontalMenu: {
                layout: 'columns',
                columns: 4
            }
        },
        subMenu: [
            {
                key: 'uiComponent.common',
                path: '',
                title: 'Common',
                translateKey: 'nav.uiComponentsCommon.common',
                icon: 'common',
                type: 'collapse',
                authority: ['admin', 'user'],
                subMenu: [
                    {
                        key: 'uiComponent.common.button',
                        path: '/button',
                        title: 'Button',
                        translateKey: 'nav.uiComponentsCommon.button',
                        icon: '',
                        type: 'item',
                        authority: ['admin', 'user'],
                        subMenu: []
                    },
                    {
                        key: 'uiComponent.common.typography',
                        path: '/typography',
                        title: 'Typography',
                        translateKey: 'nav.uiComponentsCommon.typography',
                        icon: '',
                        type: 'item',
                        authority: ['admin', 'user'],
                        subMenu: []
                    }
                ]
            }
        ]
    }
]
تنظیم آیکون ناوبری

تنظیمات آیکون ناوبری در یک فایل جداگانه در src/configs/navigation-icon.config.tsxقرار دارد

در مثال بالا، ما از مقدار رشته ای uiComponentsدر فیلد iconاستفاده می کنیم، باید سپس از این مقدار در navigation-icon.config.tsxاستفاده کنیم تا آیکون را برای تماس بازگویی کنیم.

ابتدا، آیکون مورد نظر خود را از react-iconsوارد کنید

import { FaBeer } from 'react-icons/fa'

const navigationIcon = {}

مقدار استفاده شده در iconرا تنظیم کنید و آیکون وارد شده را به عنوان مقدار

import { FaBeer } from 'react-icons/fa'

const navigationIcon = {
    uiComponents: <FaBeer />
}

اکنون آیتم منو مربوطه FaBeerرا به عنوان آیکون منو بازگویی می کند.