Reactjs 使用React传递道具呈现有效href

Reactjs 使用React传递道具呈现有效href,reactjs,Reactjs,我不熟悉react,所以要友好:-)我想把道具传递给一个链接,比如so你可以使用这个实用功能将你的文本变成slug function slugify(text){ return text.toString().toLowerCase() .replace(/\s+/g, '-') // Replace spaces with - .replace(/[^\w\-]+/g, '') // Remove all non-word chars

我不熟悉react,所以要友好:-)我想把道具传递给一个链接,比如so
你可以使用这个实用功能将你的文本变成slug

function slugify(text){
  return text.toString().toLowerCase()
    .replace(/\s+/g, '-')           // Replace spaces with -
    .replace(/[^\w\-]+/g, '')       // Remove all non-word chars
    .replace(/\-\-+/g, '-')         // Replace multiple - with single -
    .replace(/^-+/, '')             // Trim - from start of text
    .replace(/-+$/, '');            // Trim - from end of text
}
因此,如果您使用
slagify
包装this.props.text,那么您将获得相应的slug

例如:

如果
this.props.text
'Hello-World'
{slugify(this.props.text)}
将是
'Hello-World'


这一要点值得称赞:

您可以使用此实用程序功能将文本更改为slug

function slugify(text){
  return text.toString().toLowerCase()
    .replace(/\s+/g, '-')           // Replace spaces with -
    .replace(/[^\w\-]+/g, '')       // Remove all non-word chars
    .replace(/\-\-+/g, '-')         // Replace multiple - with single -
    .replace(/^-+/, '')             // Trim - from start of text
    .replace(/-+$/, '');            // Trim - from end of text
}
因此,如果您使用
slagify
包装this.props.text,那么您将获得相应的slug

例如:

如果
this.props.text
'Hello-World'
{slugify(this.props.text)}
将是
'Hello-World'


要归功于这一要点:

你描述的被称为“slug”,有很多模块可以生成它们:正是我想要的,谢谢你。你描述的被称为“slug”,有很多模块可以生成它们:正是我想要的,谢谢你。