@@ -8,52 +8,25 @@ export function useNavLink(item: DefaultTheme.NavItemWithLink) {
88 const route = useRoute ( )
99 const { withBase } = useUrl ( )
1010
11- const classes = computed ( ( ) => ( {
12- active : isActive . value ,
13- external : isExternal . value
14- } ) )
15-
16- const isActive = computed ( ( ) => {
17- return normalizePath ( withBase ( item . link ) ) === normalizePath ( route . path )
18- } )
19-
20- const isExternal = computed ( ( ) => {
21- return isExternalCheck ( item . link )
22- } )
23-
24- const href = computed ( ( ) => {
25- return isExternal . value ? item . link : withBase ( item . link )
26- } )
27-
28- const target = computed ( ( ) => {
29- if ( item . target ) {
30- return item . target
11+ const isExternal = isExternalCheck ( item . link )
12+
13+ const props = computed ( ( ) => {
14+ return {
15+ class : {
16+ active :
17+ normalizePath ( withBase ( item . link ) ) === normalizePath ( route . path ) ,
18+ isExternal
19+ } ,
20+ href : isExternal ? item . link : withBase ( item . link ) ,
21+ target : item . target || isExternal ? `_blank` : null ,
22+ rel : item . rel || isExternal ? `noopener noreferrer` : null ,
23+ 'aria-label' : item . ariaLabel
3124 }
32-
33- return isExternal . value ? '_blank' : ''
3425 } )
3526
36- const rel = computed ( ( ) => {
37- if ( item . rel ) {
38- return item . rel
39- }
40-
41- return isExternal . value ? 'noopener noreferrer' : ''
42- } )
43-
44- const ariaLabel = computed ( ( ) => item . ariaLabel )
45-
46- const text = computed ( ( ) => item . text )
47-
4827 return {
49- classes,
50- isActive,
51- isExternal,
52- href,
53- target,
54- rel,
55- ariaLabel,
56- text
28+ props,
29+ isExternal
5730 }
5831}
5932
0 commit comments