Skip to content
Discussion options

You must be logged in to vote

I tried with this:

function setFavicon(href: string, type?: string) {
  if (typeof document === "undefined") return;

  let link = document.querySelector<HTMLLinkElement>(
    'link[data-dynamic-favicon="true"]'
  );

  if (!link) {
    link = document.createElement("link");
    link.rel = "icon";
    link.setAttribute("data-dynamic-favicon", "true");
    document.head.appendChild(link);
  }

  link.rel = "icon";
  if (type) link.type = type;
  else link.removeAttribute("type");
  link.href = href;
}

Used something like:

const options: FaviconOption[] = [
  {
    label: "Default (favicon.ico)",
    href: "/favicon.ico",
    type: "image/x-icon",
  },
  { label: "Next logo SVG", href: "/ne…

Replies: 1 comment 10 replies

Comment options

You must be logged in to vote
10 replies
@InternetBowser670
Comment options

@icyJoseph
Comment options

@InternetBowser670
Comment options

@icyJoseph
Comment options

Answer selected by InternetBowser670
@InternetBowser670
Comment options

@InternetBowser670
Comment options

@InternetBowser670
Comment options

@InternetBowser670
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants