mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-08 15:10:37 +00:00
Gitbook 主题伪静态自动展开异常
This commit is contained in:
@@ -14,7 +14,7 @@ import NavPostItem from './NavPostItem'
|
|||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
const NavPostList = props => {
|
const NavPostList = props => {
|
||||||
const { filteredNavPages, post } = props
|
const { filteredNavPages } = props
|
||||||
const { locale, currentSearch } = useGlobal()
|
const { locale, currentSearch } = useGlobal()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
@@ -31,16 +31,17 @@ const NavPostList = props => {
|
|||||||
CONFIG
|
CONFIG
|
||||||
)
|
)
|
||||||
|
|
||||||
// 展开文件夹
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
// 展开文件夹
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
// 默认展开一个
|
const currentPath = decodeURIComponent(router.asPath.split('?')[0])
|
||||||
const defaultOpenIndex = getDefaultOpenIndexByPath(
|
const defaultOpenIndex = getDefaultOpenIndexByPath(
|
||||||
categoryFolders,
|
categoryFolders,
|
||||||
decodeURIComponent(router.asPath.split('?')[0])
|
currentPath
|
||||||
)
|
)
|
||||||
setExpandedGroups([defaultOpenIndex])
|
setExpandedGroups([defaultOpenIndex])
|
||||||
}, 500)
|
}, 500)
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [router, filteredNavPages])
|
}, [router, filteredNavPages])
|
||||||
|
|
||||||
// 折叠项切换,当折叠或展开数组时会调用
|
// 折叠项切换,当折叠或展开数组时会调用
|
||||||
@@ -149,19 +150,16 @@ function groupArticles(filteredNavPages) {
|
|||||||
* @returns {number} 返回需要展开的菜单索引
|
* @returns {number} 返回需要展开的菜单索引
|
||||||
*/
|
*/
|
||||||
function getDefaultOpenIndexByPath(categoryFolders, path) {
|
function getDefaultOpenIndexByPath(categoryFolders, path) {
|
||||||
// 默认展开第一个索引
|
|
||||||
let defaultIndex = 0
|
|
||||||
|
|
||||||
// 查找满足条件的第一个索引
|
// 查找满足条件的第一个索引
|
||||||
const index = categoryFolders.findIndex(group => {
|
const index = categoryFolders.findIndex(group => {
|
||||||
return group.items.some(post => path === '/' + post.slug)
|
return group.items.some(post => path === post.href)
|
||||||
})
|
})
|
||||||
|
|
||||||
// 如果找到满足条件的索引,则设置为该索引
|
// 如果找到满足条件的索引,则设置为该索引
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
defaultIndex = index
|
return index
|
||||||
}
|
}
|
||||||
|
|
||||||
return defaultIndex
|
return 0
|
||||||
}
|
}
|
||||||
export default NavPostList
|
export default NavPostList
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ const PageNavDrawer = props => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
changePageNavVisible(false)
|
changePageNavVisible(false)
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [router])
|
}, [router])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user