Skip to content

Commit 6ff48a0

Browse files
committed
v-link: handle null value (fix #181)
1 parent 48d5241 commit 6ff48a0

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/directives/link.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default function (Vue) {
7777
this.updateClasses(this.vm.$route.path)
7878
let isAbsolute = path.charAt(0) === '/'
7979
// do not format non-hash relative paths
80-
let href = router.mode === 'hash' || isAbsolute
80+
let href = path && (router.mode === 'hash' || isAbsolute)
8181
? router.history.formatPath(path, append)
8282
: path
8383
if (this.el.tagName === 'A') {

src/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ class Router {
200200
append = path.append
201201
}
202202
path = this._stringifyPath(path)
203-
this.history.go(path, replace, append)
203+
if (path) {
204+
this.history.go(path, replace, append)
205+
}
204206
}
205207

206208
/**
@@ -505,7 +507,7 @@ class Router {
505507
*/
506508

507509
_stringifyPath (path) {
508-
if (typeof path === 'object') {
510+
if (path && typeof path === 'object') {
509511
if (path.name) {
510512
var params = path.params || {}
511513
if (path.query) {
@@ -518,7 +520,7 @@ class Router {
518520
return ''
519521
}
520522
} else {
521-
return path + ''
523+
return path ? path + '' : ''
522524
}
523525
}
524526
}

0 commit comments

Comments
 (0)