Skip to content

Commit

Permalink
aa
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaMachina committed Sep 30, 2024
1 parent cd1cfb0 commit 99f7697
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/wise-cars-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'nextra-theme-docs': patch
---

handle empty `item.route` in `<FolderImpl` in `<Sidebar>` for `item.type: 'menu'`
7 changes: 3 additions & 4 deletions packages/nextra-theme-docs/src/components/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ type FolderProps = {
function FolderImpl({ item, anchors, onFocus }: FolderProps): ReactElement {
const routeOriginal = useFSRoute()
const [route] = routeOriginal.split('#')
const active = !!item.route && [route, route + '/'].includes(item.route + '/')
const hasRoute = !!item.route // for item.type === 'menu' will be ''
const active = hasRoute && [route, route + '/'].includes(item.route + '/')
const activeRouteInside =
active ||
(route !== '/' && item.route !== '' && route.startsWith(item.route + '/'))
active || (hasRoute && route.startsWith(item.route + '/'))

const focusedRoute = useContext(FocusedItemContext)
const focusedRouteInside = focusedRoute.startsWith(item.route + '/')
Expand Down Expand Up @@ -132,7 +132,6 @@ function FolderImpl({ item, anchors, onFocus }: FolderProps): ReactElement {
item.children = Object.entries(menu.items || {}).map(([key, item]) => {
const route = routes[key] || {
name: key,
...('locale' in menu && { locale: menu.locale }),
route: menu.route + '/' + key
}
return {
Expand Down

0 comments on commit 99f7697

Please sign in to comment.