From f9167f7032fd522c4c31a6bcf59ebc0f07944752 Mon Sep 17 00:00:00 2001 From: Todd Austin Date: Thu, 4 Feb 2021 11:27:21 -0600 Subject: [PATCH] fixing the canonical link --- resources/js/ui/views/ShowPost.vue | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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()