Skip to content

Instantly share code, notes, and snippets.

@lihbr
Last active February 23, 2021 14:56
Show Gist options
  • Save lihbr/91bc6fc5d1b3cc4557a53d199bce1ed6 to your computer and use it in GitHub Desktop.
Save lihbr/91bc6fc5d1b3cc4557a53d199bce1ed6 to your computer and use it in GitHub Desktop.
const ANCHOR_TAG = "a";
const FRAMEWORK_LINK = "router-link"; // or "nuxt-link", "g-link"...
const getLinkTag = ({ href, blank, external }) => {
if (blank || external) {
return ANCHOR_TAG;
} else if (/^\/(?!\/).*$/.test(href)) { // regex101.com/r/LU1iFL/1
return FRAMEWORK_LINK;
} else {
return ANCHOR_TAG;
}
};
export { getLinkTag as default, ANCHOR_TAG, FRAMEWORK_LINK };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment