Skip to content

Commit 7e572b7

Browse files
committed
exact for router-link
1 parent 0e0dc27 commit 7e572b7

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/components/link.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,27 @@ export default {
88
type: [String, Object],
99
required: true
1010
},
11-
tag: {
12-
type: String,
13-
default: 'a'
14-
},
11+
tag: String,
12+
exact: Boolean,
1513
append: Boolean,
1614
replace: Boolean,
1715
activeClass: String
1816
},
1917
render (h) {
2018
const router = this.$router
21-
const current = router.history.current
19+
const current = this.$route
2220
const to = normalizeLocation(this.to, current, this.append)
2321
const resolved = router.match(to)
2422
const fullPath = resolved.fullPath
2523
const base = router.history.base
2624
const href = base ? cleanPath(base + fullPath) : fullPath
2725
const classes = {}
2826
const activeClass = this.activeClass || router._options.linkActiveClass || 'router-link-active'
29-
classes[activeClass] = isSameLocation(resolved, this.$route)
27+
classes[activeClass] = this.exact
28+
? current.path === resolved.path
29+
: current.path.indexOf(resolved.path) === 0
3030

31-
return h(this.tag, {
31+
return h(this.tag || 'a', {
3232
attrs: { href },
3333
class: classes,
3434
on: {

0 commit comments

Comments
 (0)