在react.js的锚标记中添加参数

Adding parameter in anchor tag in react.js

本文关键字:添加 参数 react js      更新时间:2023-09-26

我试图在我的锚标记的href属性添加一个用户名。我的代码是,

var Name = React.createClass({
    render: function() {
        return (
            <div>
                <a href="www.example.com/"+ { this.props.username} +"" className="post-title">{this.props.name}</a><br />
            </div>
        );
    }
});

但是,我得到一个错误说undefined token +附近的href属性。我认为这是由于我试图在渲染方法中添加它。那么,还有其他方法吗?

谢谢. .

移除+。应该是:

<a href={"www.example.com/" + this.props.username} ...

另一种方法是:

<a href={`https://www.example.com/${this.props.username1}`}>link</a>