【发布时间】:2021-03-05 23:16:49
【问题描述】:
我在我的应用程序中集成了模板 Core UI。
重定向是在 _nav.js 上配置的,如图所示:
我在问是否可以根据这种情况隐藏或显示菜单?。
例如:根据条件显示Public Student 和隐藏Manage Convention。
菜单在 _nav.js
上定义export default [
{
_tag: 'CSidebarNavTitle',
_children: ['Menu'],
},
{
_tag: 'CSidebarNavItem',
name: 'Public Space',
to: '/home',
}, // ...
{
_tag: 'CSidebarNavItem',
name: 'Manage Convention',
to: '/manageConvention',
} // ...
]
然后,在 TheSidebar.js
上调用此 Arrayimport React from 'react'
import { useSelector, useDispatch } from 'react-redux'
import { CCreateElement, CSidebar, CSidebarBrand, CSidebarNav, CSidebarNavDivider, CSidebarNavTitle, CSidebarMinimizer, CSidebarNavDropdown, CSidebarNavItem } from '@coreui/react'
import CIcon from '@coreui/icons-react'
// sidebar nav config
import navigation from './_nav'
const TheSidebar = () => {
const dispatch = useDispatch()
const show = useSelector(state => state.sidebarShow)
return (
<CSidebar
show={show}
onShowChange={(val) => dispatch({type: 'set', sidebarShow: val })}
>
<CSidebarBrand className="d-md-down-none" to="/">
<CIcon
className="c-sidebar-brand-full"
name="logo-negative"
height={35}
/>
<CIcon
className="c-sidebar-brand-minimized"
name="sygnet"
height={35}
/>
</CSidebarBrand>
<CSidebarNav>
<CCreateElement
items={navigation}
components={{
CSidebarNavDivider,
CSidebarNavDropdown,
CSidebarNavItem,
CSidebarNavTitle
}}
/>
</CSidebarNav>
<CSidebarMinimizer className="c-d-md-down-none"/>
</CSidebar>
)
}
export default React.memo(TheSidebar)
任何建议将不胜感激。非常感谢。
【问题讨论】:
-
您的意思是根据条件隐藏/显示组件吗?问是因为这似乎很容易做到。
-
您好@Prashant Vishwakarma 先生,非常感谢您的回复。我在我的问题中添加了一个屏幕截图:我的意思是(例如):显示
Public Student和隐藏Manage Convention如果学生未获得授权。您对解决那个有什么想法吗?非常感谢先生。