Set canonical links

Search engines appear to be ok with noindex tags generated by JS, so canonical links should be fine too
This commit is contained in:
Thomas Weber committed 2021-03-15 12:04:44 -05:00
1 parent 96f4bdc91d
commit 3551988698
1 file changed
+12
+12
View File
@@ -138,6 +138,16 @@ class FileHashRouter extends HashRouter {
}
}
const getCanonicalLinkElement = () => {
let el = document.querySelector('link[rel=canonical]');
if (!el) {
el = document.createElement('link');
el.rel = 'canonical';
document.head.appendChild(el);
}
return el;
};
class WildcardRouter extends Router {
constructor (callbacks) {
super(callbacks);
@@ -211,6 +221,8 @@ class WildcardRouter extends Router {
}
const path = `${this.root}${parts.join('/')}`;
const canonical = `${location.origin}${this.root}${projectId === '0' ? '' : projectId}`;
getCanonicalLinkElement().href = canonical;
return `${path}${location.search}${location.hash}`;
}