0

this has been driving me crazy. I have an app using 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. 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' ))
John
  • 67
  • 1
  • 3
  • 10

1 Answers1

1

when I use react-router, link outside of route, there'll be warning it's forbidden. So at this time, I will use tag a or history.

Nana Sun
  • 91
  • 3