I have a NavBar with three links. If I click on a link, the URL updates and I navigate to /categories/categoryID
. The first time I click a link everything works fine. But it only works once. If I click another category (the links in my navbar change the categories) the content will not change. But it will, however, change when I refresh the browser.
- I click on the Link in the NavBar
- The url changes correctly
- the component does not re-render
- If I refresh the browser the correct content is loaded
There seems to be a disconnect between the URL and the re-rendering of components.
Question: What causes the disconnect?
I have the suspicion that the cause of this behaviour is my implementation of react router (v4).
ReactDOM.render(
<Provider store={store}>
<BrowserRouter>
<div>
<Header />
<Switch>
<Route path="/categories/index/:uuid/" component={CategoryIndex} />
<Route path="/user/signup" component={SignUpForm} />
<Route path="/user/login" component={LoginForm} />
<Route path="/home/" component={IndexPage} />
<Route/>
</Switch>
</div>
</BrowserRouter>
</Provider>
, document.getElementById('root'));
registerServiceWorker();
The component that does not re-render looks like this:
class PostList extends Component {
componentDidMount() {
const { uuid } = this.props.match.params;
this.props.fetchCategoriePosts(uuid);
}
renderPostList() {
const { category } = this.props;
if (category) {
return (
_.map(category, post => {
return(
<li className="list-group-item" key={post.uuid}>
<div>Hallo</div>
<Link to="/">{post.title}</Link>
</li>
)
}));
}
}
render() {
return (
<div className="container">
<ul className="list-goup">
{this.renderPostList()}
</ul>
</div>
);
}
}
function mapStateToProps({ category }) {
return {category}
}
export default connect(mapStateToProps, {fetchCategoriePosts}) (PostList);
Can someone help?