Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Set Canonical URL via Javascript
<script type='text/javascript'>
var link = !!document.querySelector("link[rel='canonical']") ? document.querySelector("link[rel='canonical']") : document.createElement('link');
link.setAttribute('rel', 'canonical');
link.setAttribute('href', location.protocol + '//' + location.host + location.pathname);
document.head.appendChild(link);
</script>
@bareddyyaminireddy
Copy link

bareddyyaminireddy commented Jan 22, 2021

**** metaInfo: {
link: [{ rel: "canonical", href: ${window.location} }]
} ***

we can directly add it in router if you are using vue js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment