Skip to content

Allow dynamic values in v-link #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ p.start = function (vm) {
return
}
this._started = true
this._vm = this._vm || vm
this._vm = this._vm || vm.$root
if (!this._vm) {
throw new Error(
'vue-router must be started with a root Vue instance.'
Expand Down
15 changes: 9 additions & 6 deletions src/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@ module.exports = function (Vue) {
Vue.directive('link', {

bind: function () {
var vm = this.vm
var href = this.expression
if (this.el.tagName === 'A') {
this.el.href = href
}
var self = this
this.handler = function (e) {
e.preventDefault()
vm.route._router.go(href)
self.vm.$root.route._router.go(self.destination)
}
this.el.addEventListener('click', this.handler)
},

unbind: function () {
this.el.removeEventListener('click', this.handler)
},

update: function (value) {
this.destination = value
if (this.el.tagName === 'A') {
this.el.href = value
}
}

})
Expand Down