@@ -9,9 +9,7 @@ export default function (Vue) {
9
9
10
10
Vue . directive ( 'link' , {
11
11
12
- isLiteral : true ,
13
-
14
- bind : function ( ) {
12
+ bind ( ) {
15
13
let vm = this . vm
16
14
/* istanbul ignore if */
17
15
if ( ! vm . $route ) {
@@ -31,44 +29,21 @@ export default function (Vue) {
31
29
}
32
30
}
33
31
this . el . addEventListener ( 'click' , this . handler )
34
- if ( ! this . _isDynamicLiteral ) {
35
- this . update ( this . expression )
36
- }
37
32
// manage active link class
38
33
this . unwatch = vm . $watch (
39
34
'$route.path' ,
40
35
_ . bind ( this . updateClasses , this )
41
36
)
42
37
} ,
43
38
44
- updateClasses : function ( path ) {
45
- let el = this . el
46
- let dest = this . destination
39
+ update ( path ) {
47
40
let router = this . vm . $route . router
48
- let activeClass = router . _linkActiveClass
49
- let exactClass = activeClass + '-exact'
50
- if ( this . activeRE &&
51
- this . activeRE . test ( path ) &&
52
- path !== '/' ) {
53
- _ . addClass ( el , activeClass )
54
- } else {
55
- _ . removeClass ( el , activeClass )
56
- }
57
- if ( path === dest ) {
58
- _ . addClass ( el , exactClass )
59
- } else {
60
- _ . removeClass ( el , exactClass )
61
- }
62
- } ,
63
-
64
- update : function ( path ) {
41
+ path = router . _normalizePath ( path )
65
42
this . destination = path
66
43
this . activeRE = path
67
44
? new RegExp ( '^' + path . replace ( regexEscapeRE , '\\$&' ) + '\\b' )
68
45
: null
69
46
this . updateClasses ( this . vm . $route . path )
70
- path = path || ''
71
- let router = this . vm . $route . router
72
47
let isAbsolute = path . charAt ( 0 ) === '/'
73
48
// do not format non-hash relative paths
74
49
let href = router . mode === 'hash' || isAbsolute
@@ -83,7 +58,27 @@ export default function (Vue) {
83
58
}
84
59
} ,
85
60
86
- unbind : function ( ) {
61
+ updateClasses ( path ) {
62
+ let el = this . el
63
+ let dest = this . destination
64
+ let router = this . vm . $route . router
65
+ let activeClass = router . _linkActiveClass
66
+ let exactClass = activeClass + '-exact'
67
+ if ( this . activeRE &&
68
+ this . activeRE . test ( path ) &&
69
+ path !== '/' ) {
70
+ _ . addClass ( el , activeClass )
71
+ } else {
72
+ _ . removeClass ( el , activeClass )
73
+ }
74
+ if ( path === dest ) {
75
+ _ . addClass ( el , exactClass )
76
+ } else {
77
+ _ . removeClass ( el , exactClass )
78
+ }
79
+ } ,
80
+
81
+ unbind ( ) {
87
82
this . el . removeEventListener ( 'click' , this . handler )
88
83
this . unwatch && this . unwatch ( )
89
84
}
0 commit comments