我是新来的反应者,正在学习获取,但是我坚持了发布请求。
我想做类似的事情,当用户单击按钮时,发生发布请求,我从请求中获取ID并重定向到Fight / ID
我的路线是在 index.js 中设置的,那不是问题
这是我的子组件
function Fight(props){
if(props.other === 3) {
return(
<div className="row">
<button className="btn btn-danger"> Fight</button>
<p><i>Your team is ready to fight </i></p>
</div>
)
}
答案 0 :(得分:1)
感谢路由器的public ActionResult Details(int Id = 1)
{
MoviesData movie = db.MoviesData.Find(Id);
MovieViewModel MovieVM = new MovieViewModel{
MovieID = movie.MovieID,
MovieName = movie.MovieName,
MovieDescription = movie.MovieDescription,
MovieCategory = movie.MovieCategory,
MovieYear = movie.MovieYear
};
return View(MovieVM);
}
道具可以像这样包装您的组件:
history
例如,在import React, { Component } from 'react';
import { Router, Route, Switch } from 'react-router-dom';
import { createBrowserHistory } from 'history';
class App extends Component {
render () {
return (
<Router history={history}>
<Switch>
<Route exact path="/home" component={Home}/>
</Switch>
</Router>
);
}
}
export default App;
组件中,您有一个Home
和一个div
:
您只需这样做:
onClick