How to make a link clickable in React.Js inside render? If I click the link it goes to home page. I want to follow the link only. my code looks like this
<tr>
<td>IPFS Hash # stored on Eth Contract</td>
<td><a href= "#">{"https://gateway.ipfs.io/ipfs/"+this.state.ipfsHash}</a></td>
</tr>
To add the link in the menu, use the <NavLink /> component by react-router-dom . The NavLink component provides a declarative way to navigate around the application. It is similar to the Link component, except it can apply an active style to the link if it is active.
js as follows. import React from 'react'; import ReactDOM from 'react-dom'; import { BrowserRouter, Switch, Route } from 'react-router-dom'; import Home from './Home'; import Contact from './Contact'; import Header from './App'; We will use the render function of ReactDOM imported in line 2.
To add an external link with React Router, we can set the to prop to an object with the pathname property set to the external URL we go to when the link is clicked. to set the to prop to { pathname: "https://example.com" } to go to https://example.com when we click on the link.
The React way to add a click and redirect is to use the Link to provided by the react-router-
Inside the component
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>
}
}
In route file
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>
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With