Answer the question
In order to leave comments, you need to log in
Svg icons in SPA?
Hello! More recently, I began to understand and work with single page app, hence the question, how to work with svg icons? What is the best way to pack them?
I like this approach:
define all the icons inside the tag in SVG, but hide them. Then refer to each when needed using the element, referencing with xlink:href="#id"
Answer the question
In order to leave comments, you need to log in
I wrote a gulp plugin for this that does the insertion and processing for me svgstore
SVG does not support dynamic change of the xlink:href attribute, so for such icons you need to write a separate mini-component that will simply dynamically insert an element with a link inside into the page. So, according to the results, it will be even easier, because you can attach a bunch of your custom attributes to this component, so that later the whole thing can be easily styled, without forcing yourself at every step to stuff a wretched design in the form
<svg>
<use blah blah>
</svg>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question