Skip to content

Instantly share code, notes, and snippets.

@AlkarE
Forked from lihbr/SmartLink.Vue3.js
Created January 10, 2021 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlkarE/94d129f29e51acd0ccc1dd63ea2e9e70 to your computer and use it in GitHub Desktop.
Save AlkarE/94d129f29e51acd0ccc1dd63ea2e9e70 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