@@ -9,9 +9,7 @@ export default function (Vue) {
99
1010 Vue . directive ( 'link' , {
1111
12- isLiteral : true ,
13-
14- bind : function ( ) {
12+ bind ( ) {
1513 let vm = this . vm
1614 /* istanbul ignore if */
1715 if ( ! vm . $route ) {
@@ -31,44 +29,21 @@ export default function (Vue) {
3129 }
3230 }
3331 this . el . addEventListener ( 'click' , this . handler )
34- if ( ! this . _isDynamicLiteral ) {
35- this . update ( this . expression )
36- }
3732 // manage active link class
3833 this . unwatch = vm . $watch (
3934 '$route.path' ,
4035 _ . bind ( this . updateClasses , this )
4136 )
4237 } ,
4338
44- updateClasses : function ( path ) {
45- let el = this . el
46- let dest = this . destination
39+ update ( path ) {
4740 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 )
6542 this . destination = path
6643 this . activeRE = path
6744 ? new RegExp ( '^' + path . replace ( regexEscapeRE , '\\$&' ) + '\\b' )
6845 : null
6946 this . updateClasses ( this . vm . $route . path )
70- path = path || ''
71- let router = this . vm . $route . router
7247 let isAbsolute = path . charAt ( 0 ) === '/'
7348 // do not format non-hash relative paths
7449 let href = router . mode === 'hash' || isAbsolute
@@ -83,7 +58,27 @@ export default function (Vue) {
8358 }
8459 } ,
8560
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 ( ) {
8782 this . el . removeEventListener ( 'click' , this . handler )
8883 this . unwatch && this . unwatch ( )
8984 }
0 commit comments