Use exact
Change this
<Route path="/user/:user_id" component={UserComponent} onEnter={fetchUser} />
To this
<Route exact path="/user/:user_id" component={UserComponent} onEnter={fetchUser} />
I guess you still render UserComponent
even if you use other path is because it share the same /user
path
[EDIT]
The problem is because react-router didn't detect either it's a number or character maybe you could differentiate the path? like this
<Route path="/user/id/:user_id" component={UserComponent} onEnter={fetchUser} />
<Route path="/user/name/:user_name" component={ProfileComponent} onEnter={fetchProfile} />
[UPDATE]
My solution is to check the params type
Since you use react router v2.8.1 you might declare a component wrapper to decide which component should render.
function CheckUserComponent(props) {
if (!Number.isNaN(parseFloat(props.match.params.user)) && Number.isFinite(props.match.params.user)) {
return <UserComponent />
} else {
return <ProfileComponent />
}
}
<Route path="/user/:user" component={CheckUserComponent} onEnter={fetchUser} />