【发布时间】:2015-04-14 15:43:45
【问题描述】:
我有这个反应组件,当我渲染它时它会起作用
var Postlist = React.createClass({
getInitialState: function () {
socket.on("new",this.Updatepost);
return {posts: [], hasMore: true, onView: 5};
},
componentWillMount: function () {
this.state.posts.push(this.props.newposts);
this.setState({posts: this.props.newposts});
},
$.ajax({
url: 'load_posts.php',
dataType: 'json',
success: function (data) {
var x = data;
React.render(<Postlist newposts={x} />,document.getElementById("main"));
}.bind(this),
error: function (xhr, status, err) {
console.error(this.props.url, status, err.toString());
}.bind(this)
});
但我使用历史 API 在页面之间导航
那么我如何在导航时卸载和重新安装反应组件以及如何在反应代码之外卸载它
【问题讨论】:
-
您是否考虑过使用任何对 React 友好的路由组件?
标签: url-routing reactjs html5-history