From 6e9238808c2f5fe79c1bbfd9bd992b6c7ddd5f05 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Fri, 29 May 2015 15:31:06 -0700 Subject: [PATCH] Allow dynamic values in v-link --- src/index.js | 2 +- src/link.js | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/index.js b/src/index.js index b4e9eb488..683ed15d3 100644 --- a/src/index.js +++ b/src/index.js @@ -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.' diff --git a/src/link.js b/src/link.js index 3c0a380f6..6c47dbb17 100644 --- a/src/link.js +++ b/src/link.js @@ -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 + } } })