Skip to content

Commit

Permalink
feat(useFavicon): Add link tag if it doesn't exist (#3444)
Browse files Browse the repository at this point in the history
  • Loading branch information
babu-ch committed Oct 7, 2023
1 parent 81a06dd commit d1fcc57
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/core/useFavicon/index.ts
Expand Up @@ -38,9 +38,19 @@ export function useFavicon(
const favicon = toRef(newIcon)

const applyIcon = (icon: string) => {
document?.head
const elements = document?.head
.querySelectorAll<HTMLLinkElement>(`link[rel*="${rel}"]`)
.forEach(el => el.href = `${baseUrl}${icon}`)
if (!elements || elements.length === 0) {
const link = document?.createElement('link')
if (link) {
link.rel = rel
link.href = `${baseUrl}${icon}`
link.type = `image/${icon.split('.').pop()}`
document?.head.append(link)
}
return
}
elements?.forEach(el => el.href = `${baseUrl}${icon}`)
}

watch(
Expand Down

0 comments on commit d1fcc57

Please sign in to comment.