There are two approaches here, both quite simple.
Approach 1. Using React Router
Make sure you already have a route in your project. It should contain this information as a minimum: path and component. It should be defined something like this:
import YourComponent from "./path/of/your/component";
<Route path="/insert/your/path/here" component={YourComponent} />
handleClick, Link react-router-dom (, , , npm i react-router-dom).
( handleClick Link):
handleClick(){
alert('---');
}
render() {
return <button onClick={this.handleClick}>hello</button>
}
}
:
render() {
return (
<div>
<Link to="/insert/your/path/here" className="btn btn-primary">hello</Link>
</div>
);
}
}
Link , , , .
.
//
import YourComponent from "./path/of/your/component";
<Router>
<Route exact path="/insert/your/path/here" component={YourComponent} />
</Router>
// handleClick
import { Link } from "react-router-dom";
class App extends Component {
render() {
return(
<div>
<Link to="/insert/your/path/here" className="btn btn-primary">hello</Link>
</div>
);
}
}
2: window.open
, , . , Link, , handleClick. , .
:
handleClick(){
alert('---');
}
:
handleClick(){
window.open("/insert/your/path/here");
//this opens in a new tab (believe that is what the owner of the question wanted if not you can do window.location.href = "/insert/your/path/here".
}
. , , id .. . .
, . , .
:
<Route path="/insert/your/path/here/:name" component={YourComponent} />
(:), .
:
<Link to={'/insert/your/path/here/${variableName}'}>hello</Link>
window.open, :
window.open('/insert/your/path/here/${variableName}');
, . , React, , . , " React, , : , , , ". $ {} , React . , , : " "/insert/your/path/here/valueOfVariablName ", React , -, "/insert/your/path//: ": OfVariableName. , . . . , , ..
React-Router . : https://medium.com/@pshrmn/a-simple-react-router-v4-tutorial-7f23ff27adf
. , .
, , . , Link. , , , .