Commit 617458873f76e6b65ff62b89a3ccfc55ca9c05d6
1 parent
467e2cf9
Update link mixin to resolve url from router if possible
Showing
1 changed file
with
20 additions
and
2 deletions
Show diff stats
src/mixins/link.js
| ... | ... | @@ -15,12 +15,30 @@ export default { |
| 15 | 15 | return oneOf(value, ['_blank', '_self', '_parent', '_top']); |
| 16 | 16 | }, |
| 17 | 17 | default: '_self' |
| 18 | - } | |
| 18 | + }, | |
| 19 | + append: { | |
| 20 | + type: Boolean, | |
| 21 | + required: false, | |
| 22 | + default: false, | |
| 23 | + }, | |
| 19 | 24 | }, |
| 20 | 25 | computed: { |
| 21 | 26 | linkUrl () { |
| 22 | 27 | const type = typeof this.to; |
| 23 | - return type === 'string' ? this.to : null; | |
| 28 | + if (type !== 'string') { | |
| 29 | + return null; | |
| 30 | + } | |
| 31 | + if (this.to.includes('//')) { | |
| 32 | + /* Absolute URL, we do not need to route this */ | |
| 33 | + return this.to; | |
| 34 | + } | |
| 35 | + const router = this.$router; | |
| 36 | + if (router) { | |
| 37 | + const current = this.$route; | |
| 38 | + const route = router.resolve(this.to, current, this.append); | |
| 39 | + return route ? route.href : null; | |
| 40 | + } | |
| 41 | + return this.to; | |
| 24 | 42 | } |
| 25 | 43 | }, |
| 26 | 44 | methods: { | ... | ... |