File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change 1
1
import { cleanPath , getFullPath } from '../util/path'
2
- import { normalizeLocation } from '../util/location'
2
+ import { normalizeLocation , isSameLocation } from '../util/location'
3
3
4
4
export default {
5
5
name : 'router-link' ,
@@ -13,20 +13,26 @@ export default {
13
13
default : 'a'
14
14
} ,
15
15
append : Boolean ,
16
- replace : Boolean
16
+ replace : Boolean ,
17
+ activeClass : {
18
+ type : String ,
19
+ default : 'router-link-active'
20
+ }
17
21
} ,
18
22
render ( h ) {
19
23
const router = this . $router
20
24
const current = router . history . current
21
25
const to = normalizeLocation ( this . to , current , this . append )
22
- const fullPath = to . name
23
- ? router . match ( to ) . fullPath
24
- : getFullPath ( to )
26
+ const resolved = router . match ( to )
27
+ const fullPath = resolved . fullPath
25
28
const base = router . history . base
26
29
const href = base ? cleanPath ( base + fullPath ) : fullPath
30
+ const classes = { }
31
+ classes [ this . activeClass ] = isSameLocation ( resolved , this . $route )
27
32
28
33
return h ( this . tag , {
29
34
attrs : { href } ,
35
+ class : classes ,
30
36
on : {
31
37
click : ( e ) => {
32
38
e . preventDefault ( )
You can’t perform that action at this time.
0 commit comments