[英]React router: Link changes url but doesn't load component
this has been driving me crazy. 这一直让我发疯。 I have an app using react-router.
我有一个使用react-router的应用程序。 When I load from the server everything works correctly.
当我从服务器加载时,一切正常。 But when I try to hit a route through the Link component, it just changes the url and the component doesn't get loaded.
但是,当我尝试通过Link组件查找路由时,它只会更改url,并且不会加载该组件。 Someone please help me how to solve this problem .
请有人帮我解决这个问题。
class Example extends React.Component {
constructor(props) {
super(props);
this.state = {
Item: 5,
skip: 0
}
this.handleClick = this.handleClick.bind(this);
}
urlParams() {
return `http://localhost:3001/meetups?filter[limit]=${(this.state.Item)}&&filter[skip]=${this.state.skip}`
}
handleClick() {
this.setState({skip: this.state.skip + 1})
}
render() {
return (
<div>
<a href={this.urlParams()}>Example link</a>
<pre>{this.urlParams()}</pre>
<button onClick={this.handleClick}>Change link</button>
</div>
)
}
}
ReactDOM.render(<Example/>, document.querySelector('div#my-example' ))
when I use react-router, link outside of route, there'll be warning it's forbidden. 当我使用react-router时,在路由之外进行链接时,会警告它被禁止。 So at this time, I will use tag a or history.
因此,此时,我将使用标记a或历史记录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.