Last active
August 10, 2017 03:40
-
-
Save jokemmy/3c2241d8c9f4fc88a14082511febd976 to your computer and use it in GitHub Desktop.
Use SVG icon with svg-sprite-loader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 现用方案 | |
function IconSVG({ xlinkHref, className, ...props }) { | |
const clsName = className ? `${styles.iconSVG} ${className}` : styles.iconSVG; | |
return ( | |
<svg aria-hidden="true" className={clsName} {...props}> | |
{/** | |
* 会出现 bug 的场景:使用 browserHistory,并且页面内使用 href 属性非空的 <base /> 标签 | |
* 如果不加 pathname,在火狐或者某国产双核浏览器中以及安卓版微信浏览器中图标不显示 | |
*/} | |
<use xlinkHref={location.pathname + xlinkHref} /> | |
</svg> | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// svg-sprite-loader 官方提供的方法 | |
function IconSVG({ xlinkHref, className, ...props }) { | |
const clsName = className ? `${styles.iconSVG} ${className}` : styles.iconSVG; | |
return ( | |
<svg aria-hidden="true" className={clsName} {...props}> | |
<use xlinkHref={xlinkHref} /> | |
</svg> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment