diff --git a/resources/js/ui/views/ShowPost.vue b/resources/js/ui/views/ShowPost.vue index 76cd76cfb..cff6ea1f5 100644 --- a/resources/js/ui/views/ShowPost.vue +++ b/resources/js/ui/views/ShowPost.vue @@ -174,6 +174,15 @@ export default { async created() { await Promise.all([this.fetchPost()]); + + // Hack since vue-meta doesn't seem to like canonical tags + if (this.post?.meta?.canonical_link != null) { + let link = document.createElement('link'); + link.rel = 'canonical'; + link.href = this.post.meta.canonical_link; + document.head.appendChild(link); + } + this.isReady = true; NProgress.done(); }, @@ -188,6 +197,12 @@ export default { }); }, + beforeRouteLeave(to, from, next) { + // Hack to remove the canonical tag when you navigate away + document.querySelector('link[rel="canonical"]').remove(); + next(); + }, + methods: { fetchPost() { return this.request()