Reactjs 反应-使用重定向链接按钮
我不熟悉Reactjs 反应-使用重定向链接按钮,reactjs,redirect,href,Reactjs,Redirect,Href,我不熟悉React,如果这太基本,我很抱歉 我正在尝试在我的应用程序中添加一个按钮,将其重定向到Spotify 到目前为止,我正试图这样做 class Spotify extends Component { constructor () { super() this.handleClick = this.handleClick.bind(this) } handleClick () { console.log('Success!') } rende
React
,如果这太基本,我很抱歉
我正在尝试在我的应用程序中添加一个按钮,将其重定向到Spotify
到目前为止,我正试图这样做
class Spotify extends Component {
constructor () {
super()
this.handleClick = this.handleClick.bind(this)
}
handleClick () {
console.log('Success!')
}
render () {
return (
<div className='button__container'>
<button className='button' onClick={this.handleClick}>
Link your Spotify account
</button>
</div>
)
}
}
export default Spotify;
类Spotify扩展组件{
构造函数(){
超级()
this.handleClick=this.handleClick.bind(this)
}
handleClick(){
console.log('Success!')
}
渲染(){
返回(
链接您的Spotify帐户
)
}
}
导出默认的Spotify;
现在,将上述按钮链接到以下位置的最佳方式是:
<a href="http://localhost:8888"></a>
我想你正在寻找这样的东西:
class Spotify extends Component {
render () {
return (
<div className='button__container'>
<a className='button' role="button" href="http://someurl.com">
Link your Spotify account
</a>
</div>
)
}
}
export default Spotify;
类Spotify扩展组件{
渲染(){
返回(
)
}
}
导出默认的Spotify;
如果组件不需要状态,请考虑将上述代码重构为无状态组件,如::/P>
export const Spotify = () => (
<div className='button__container'>
<a className='button' role="button" href="http://someurl.com">
Link your Spotify account
</a>
</div>
);
export const Spotify=()=>(
);
如果您只是试图显示链接,锚定标记将正常工作。您可以将
target=“\u blank”
添加到锚定标记中,以便在新选项卡中打开它。您不能只添加本地主机的任何特定原因:8888“>你的车在哪里?马上!我在作者的问题中添加了一条评论,因为我想了解是什么让他们认为他们不能继续使用锚而不是按钮。实际上,我需要状态,因为我需要这个按钮只有在用户尚未通过身份验证时才会出现。您能更新您的答案吗?我的意思是保留onClick
功能