【问题标题】:How to make a link clickable in React.Js inside render?如何在 React.Js 内部渲染中使链接可点击?
【发布时间】:2019-05-09 10:12:24
【问题描述】:

如何在 React.Js 内部渲染中使链接可点击?如果我单击链接,它将转到主页。我只想关注链接。 我的代码是这样的

              <tr>
                <td>IPFS Hash # stored on Eth Contract</td>

                <td><a href= "#">{"https://gateway.ipfs.io/ipfs/"+this.state.ipfsHash}</a></td>
              </tr>

【问题讨论】:

    标签: html reactjs render


    【解决方案1】:

    React 添加点击和重定向的方式是使用 react-router 提供的 Link-

    组件内部

    import {Link} from 'react-router-dom;
    class Parent extends React.Component{
        render(){
             <div><Link to="/home">Click here to go back to home page</Link></div>
        } 
    }
    

    在路由文件中

    import React from 'react';
    import {BrowserRouter as Router,Switch} from 'react-router-dom;
    export class RoutingClass extends React.Component{
        render(){
            <Router>
                <Switch>
                    <Route exact path="/home" component={Home} />
                </Switch>
            </Router>
        }
    }
    

    【讨论】:

      【解决方案2】:

      我希望我能理解你的问题,我想你要找的是

        <tr>
           <td>IPFS Hash # stored on Eth Contract</td>
           <td><a href={"https://gateway.ipfs.io/ipfs/"+this.state.ipfsHash}>Click here to go to home page</a></td>
        </tr>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-06-19
        • 2016-06-28
        • 2014-08-21
        • 1970-01-01
        • 2023-04-05
        • 2021-10-19
        • 1970-01-01
        相关资源
        最近更新 更多