I have a navigation sidebar that includes nested v-list-groups. Based on the documentation, the "group" prop of v-list-group should expand based on the route namespace.
To see more information, visit: https://vuetifyjs.com/en/components/lists/
While this functionality works well with the top-level v-list-group, it opens up when the page is reloaded and the route matches the "group" prop.
However, this feature does not work for the sub-group v-list-groups. Upon reloading the page, I notice the subgroup closing, indicating that the group prop is working but something is causing it to close immediately after.
The code can be a bit complex, especially with variable naming. It involves rendering a list of navigation items where items without a subgroup defined appear as regular items, while those with a subgroup render as subgroups. This structure goes two levels deep.
This approach allows me to define the entire navigation bar in a single JSON file and import it into my project.
<template>
<v-list dense nav>
<template v-for="(sidebarItem, sidebarIndex) in sidebarItems">
<v-list-item
v-if="arrayIsEmptyOrUndefined(sidebarItem.subGroup)"
:key="sidebarIndex"
:to="sidebarItem.linkTo"
nuxt
>
<v-list-item-action>
<v-icon>{{ sidebarItem.icon }}</v-icon>
</v-list-item-action>
<v-list-item-content>
<v-list-item-title v-text="sidebarItem.title" />
</v-list-item-content>
</v-list-item>
<v-list-group
v-if="
(!arrayIsEmptyOrUndefined(sidebarItem.subGroup) &&
typeof sidebarItem.subGroup !== 'undefined')
"
:key="sidebarIndex"
:prepend-icon="sidebarItem.icon"
:group="sidebarItem.linkTo"
>
<template v-slot:activator>
<v-list-item-content>
<v-list-item-title>{{ sidebarItem.title }}</v-list-item-title>
</v-list-item-content>
</template>
<v-list-item
v-if="arrayIsEmptyOrUndefined(sidebarItem.subGroup)"
:key="subGroupIndex"
:to="sidebarItem.linkTo"
nuxt
>
<v-list-item-action>
<v-icon>{{ sidebarItem.icon }}</v-icon>
</v-list-item-action>
<v-list-item-content>
<v-list-item-title v-text="sidebarItem.title" />
</v-list-item-content>
</v-list-item>
<template v-for="(subGroupItem, subGroupIndex) in sidebarItem.subGroup">
<v-list-item
v-if="arrayIsEmptyOrUndefined(subGroupItem.subGroup)"
:key="subGroupIndex"
:to="subGroupItem.linkTo"
nuxt
>
<v-list-item-action>
<v-icon>{{ subGroupItem.icon }}</v-icon>
</v-list-item-action>
<v-list-item-content>
<v-list-item-title v-text="subGroupItem.title" />
</v-list-item-content>
</v-list-item>
<v-list-group
v-if="
(!arrayIsEmptyOrUndefined(subGroupItem.subGroup) &&
typeof subGroupItem.subGroup !== 'undefined')
"
:key="subGroupIndex"
sub-group
:group="subGroupItem.linkTo"
>
<template v-slot:activator>
<v-list-item-content>
<v-list-item-title>{{ subGroupItem.title }}</v-list-item-title>
</v-list-item-content>
</template>
<v-list-item
v-for="(subGroupSubGroupItem, subGroupSubGroupIndex) in subGroupItem.subGroup"
:key="subGroupSubGroupIndex"
:to="subGroupSubGroupItem.linkTo"
nuxt
exact
>
<v-list-item-content>
<v-list-item-title v-text="subGroupSubGroupItem.title" />
</v-list-item-content>
<v-list-item-action>
<v-icon>{{ subGroupSubGroupItem.icon }}</v-icon>
</v-list-item-action>
</v-list-item>
</v-list-group>
</template>
</v-list-group>
</template>
</v-list>
</template>
If both the group and subgroup match the route namespace, only the group expands. The Vuetify documentation website provides a functional example of this behavior. If you navigate to a sub-group and refresh the page, the sub-group remains open.