The menu items in my dropdown are stored in an array called "lis". When the dropdown is open, the lis are mapped into it. Now I want to take the names not only as content, but also as a path to open the pages. And it works. My only problem is that some of the lis consist of two words. And I can’t have a pathname with spaces. How can I remove this whitespace?
I tried to predefine it with lis.join(""), but the console tells me, undefined, so I obviously must find a way to do that in the map function.
code:
{
item.lis.map((li, index)=>(
<ul key={index}>
<DropDownLi><Link to={{pathname:`/${li}`}} className="link" style={{color:"black"}}>{li}</Link></DropDownLi>
</ul>
))
}
>Solution :
you could use replace to remove spaces, as str.replace(/\s+/g, '') which replaces spaces,
{
item.lis.map((li, index)=>(
<ul key={index}>
<DropDownLi><Link to={{pathname:`/${li.replace(/\s+/g, '')}`}} className="link" style={{color:"black"}}>{li}</Link></DropDownLi>
</ul>
))
}