我正在使用React-router,当我点击链接按钮时它工作正常,但是当我刷新我的网页时它没有加载我想要的东西.
例如,我进入localhost/joblist,一切都很好,因为我来到这里按一个链接.但是,如果我刷新网页,我得到:不能GET/joblist
默认情况下它没有像这样工作.最初我有我的URL:localhost /#/和localhost /#/ joblist,他们工作得非常好.但是我不喜欢这种网址,所以试图抹去我写的'#':
Cannot GET /joblist
Run Code Online (Sandbox Code Playgroud)
localhost /不会发生这个问题,这个问题总是返回我想要的.
编辑:这个应用程序是单页面,因此/ joblist不需要向任何服务器询问任何内容.
EDIT2:我的整个路由器.
Router.run(routes, Router.HistoryLocation, function (Handler) {
React.render(<Handler/>, document.body);
});
Run Code Online (Sandbox Code Playgroud) 我在同时使用 React JS 和 canvas 时遇到问题。
一切似乎都工作顺利,但是当由于我的应用程序画布闪烁的其他部分的变化而调用渲染方法时。看起来 React 正在将它重新附加到 DOM 中(也许是因为我在它上面播放动画并且它的绘制帧每次都不同)。
这是我的渲染方法:
render: function() {
var canvasStyle = {
width: this.props.width
};
return (
<canvas id="interactiveCanvas" style={canvasStyle}/>
);
}
Run Code Online (Sandbox Code Playgroud)
作为临时解决方案,我手动附加画布标签,无需使用reactjs:
render: function() {
var canvasStyle = {
width: this.props.width
};
return (
<div id="interactivediv3D">
</div>
);
}
Run Code Online (Sandbox Code Playgroud)
进而:
componentDidMount: function() {
var canvasStyle = {
width: this.props.width
};
var el = document.getElementById('interactivediv3D');
el.innerHTML = el.innerHTML +
'<canvas id="interactive3D" style={'+canvasStyle+'}/>';
},
Run Code Online (Sandbox Code Playgroud)
它工作正常。但我认为这不是一个干净的方法,最好使用reactjs 渲染这个canvas 标签。
知道如何解决这个问题吗?或者至少避免当仅绘制的框架发生变化时,reactjs 重新渲染此画布。