functionguardEvent (e) { // don't redirect with control keys if (e.metaKey || e.altKey || e.ctrlKey || e.shiftKey) return // don't redirect when preventDefault called if (e.defaultPrevented) return // don't redirect on right click if (e.button !== undefined && e.button !== 0) return // don't redirect if `target="_blank"` if (e.currentTarget && e.currentTarget.getAttribute) { const target = e.currentTarget.getAttribute('target') if (/\b_blank\b/i.test(target)) return } // this may be a Weex event which doesn't have this method if (e.preventDefault) { e.preventDefault() } returntrue }
// src/components/link.js exportdefault { render () { // Omitted... if (this.tag === 'a') { data.on = on data.attrs = { href, 'aria-current': ariaCurrentValue } } else { // find the first <a> child and apply listener and href const a = findAnchor(this.$slots.default) if (a) { // in case the <a> is a static node a.isStatic = false const aData = (a.data = extend({}, a.data)) aData.on = aData.on || {} // transform existing events in both objects into arrays so we can push later for (const event in aData.on) { const handler = aData.on[event] if (event in on) { aData.on[event] = Array.isArray(handler) ? handler : [handler] } } // append new listeners for router-link for (const event in on) { if (event in aData.on) { // on[event] is always a function aData.on[event].push(on[event]) } else { aData.on[event] = handler } }
const aAttrs = (a.data.attrs = extend({}, a.data.attrs)) aAttrs.href = href aAttrs['aria-current'] = ariaCurrentValue } else { // doesn't have <a> child, apply listener to self data.on = on } }