1
1
import { defineComponent , h , onMounted , ref , resolveComponent } from 'vue'
2
2
import { RouterLink , useRoute } from 'vue-router'
3
3
4
- import { CBadge , CSidebarNav , CNavItem , CNavGroup , CNavTitle } from '@coreui/vue'
4
+ import {
5
+ CBadge ,
6
+ CSidebarNav ,
7
+ CNavItem ,
8
+ CNavGroup ,
9
+ CNavTitle ,
10
+ } from '@coreui/vue'
5
11
import nav from '@/_nav.js'
6
12
7
13
const normalizePath = ( path ) =>
8
- decodeURI ( path )
9
- . replace ( / # .* $ / , '' )
10
- . replace ( / ( i n d e x ) ? \. ( h t m l ) $ / , '' )
14
+ decodeURI ( path )
15
+ . replace ( / # .* $ / , '' )
16
+ . replace ( / ( i n d e x ) ? \. ( h t m l ) $ / , '' )
11
17
12
18
const isActiveLink = ( route , link ) => {
13
- if ( link === undefined ) {
14
- return false
15
- }
19
+ if ( link === undefined ) {
20
+ return false
21
+ }
16
22
17
- if ( route . hash === link ) {
18
- return true
19
- }
23
+ if ( route . hash === link ) {
24
+ return true
25
+ }
20
26
21
- const currentPath = normalizePath ( route . path )
22
- const targetPath = normalizePath ( link )
27
+ const currentPath = normalizePath ( route . path )
28
+ const targetPath = normalizePath ( link )
23
29
24
- return currentPath === targetPath
30
+ return currentPath === targetPath
25
31
}
26
32
27
33
const isActiveItem = ( route , item ) => {
28
- if ( isActiveLink ( route , item . to ) ) {
29
- return true
30
- }
34
+ if ( isActiveLink ( route , item . to ) ) {
35
+ return true
36
+ }
31
37
32
- if ( item . items ) {
33
- return item . items . some ( ( child ) => isActiveItem ( route , child ) )
34
- }
38
+ if ( item . items ) {
39
+ return item . items . some ( ( child ) => isActiveItem ( route , child ) )
40
+ }
35
41
36
- return false
42
+ return false
37
43
}
38
44
39
45
const AppSidebarNav = defineComponent ( {
@@ -56,7 +62,9 @@ const AppSidebarNav = defineComponent({
56
62
return h (
57
63
CNavGroup ,
58
64
{
59
- ...firstRender . value && { visible : item . items . some ( ( child ) => isActiveItem ( route , child ) ) }
65
+ ...( firstRender . value && {
66
+ visible : item . items . some ( ( child ) => isActiveItem ( route , child ) ) ,
67
+ } ) ,
60
68
} ,
61
69
{
62
70
togglerContent : ( ) => [
0 commit comments