Skate to Eat
Skate to Eat

Reputation: 2844

React reload component on dynamic route

<Route path="/user/:username/" component={UserProfile} />

I have a route set up like above and having issue on

<Link to={"/user/" + userName + "/"}>user profile</Link>

When user goes to /user/user1/ to /user/user2/ because it does not reload the component but just update the states.

What is the best way to solve this issue? I need HTTP request in componentDidMount to be executes when username changes.

Upvotes: 0

Views: 1051

Answers (1)

Tharaka Wijebandara
Tharaka Wijebandara

Reputation: 8065

Routed component doesn't reload when route parameters change. But it will call componentWillReceiveProps() as the component get different props. So call HTTP request inside both componentWillReceiveProps() and componentDidMount as React doesn't call componentWillReceiveProps() with initial props during mounting.

Upvotes: 2

Related Questions