[CST-5729] Method to remove Link tags from Head when switched page

This commit is contained in:
Alban Imami
2023-05-12 16:01:19 +02:00
parent 6f4b0ad6b1
commit 22fbcbebfa

View File

@@ -64,6 +64,11 @@ const tagsInUseSelector =
(state: MetaTagState) => state.tagsInUse, (state: MetaTagState) => state.tagsInUse,
); );
/**
* Link elements added on Item Page
*/
let linkTags = [];
@Injectable() @Injectable()
export class MetadataService { export class MetadataService {
@@ -119,6 +124,7 @@ export class MetadataService {
private processRouteChange(routeInfo: any): void { private processRouteChange(routeInfo: any): void {
this.clearMetaTags(); this.clearMetaTags();
this.clearLinkTags();
if (hasValue(routeInfo.data.value.dso) && hasValue(routeInfo.data.value.dso.payload)) { if (hasValue(routeInfo.data.value.dso) && hasValue(routeInfo.data.value.dso.payload)) {
this.currentObject.next(routeInfo.data.value.dso.payload); this.currentObject.next(routeInfo.data.value.dso.payload);
@@ -207,27 +213,14 @@ export class MetadataService {
link.rel = rel; link.rel = rel;
link.type = type; link.type = type;
document.head.appendChild(link); document.head.appendChild(link);
console.log(link); linkTags.push(link);
} }
// public setSignpostingLinksets(itemId: string) { public clearLinkTags(){
// let linkSet: string; linkTags.forEach(link => {
link.parentNode.removeChild(link);
// const value = this.signpostginDataService.getLinksets(itemId); });
}
// value.subscribe(linksets => {
// linkSet = linksets.payload.body;
// });
// return linkSet;
// }
// setLinkAttribute(linksets){
// console.log('ANDREA', linksets);
// const linkAttribute = `Link: ${linksets.payload.body}`;
// const textNode = document.createTextNode(linkAttribute);
// document.head.appendChild(textNode);
// }
/** /**
* Add <meta name="title" ... > to the <head> * Add <meta name="title" ... > to the <head>