Skip to content

Commit

Permalink
fixing the canonical link
Browse files Browse the repository at this point in the history
  • Loading branch information
austintoddj committed Feb 4, 2021
1 parent 76c320d commit f9167f7
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions resources/js/ui/views/ShowPost.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
Expand All @@ -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()
Expand Down

0 comments on commit f9167f7

Please sign in to comment.