Each time you perform the action of the root component in react-router-4?

There are for example the following URLs:


At the root url component is rendered <app></app>in componentDidMount which is performed a certain action. When I go to url on (/foo, /foo/3) then be loaded on other components, but the action component of the App no longer works, that is logical.

And how to make it so that every time worked? To throw is that action in componentWillUpdate - but it's crazy, he will too often be called..
June 10th 19 at 14:57
1 answer
June 10th 19 at 14:59
Do this:

import React { Component } from 'react';
import { withRouter } from 'react-router-dom';
import { someAcion } from '../somePlace';

class App extends Component {
 componentWillReciveProps(nextProps) {
 if (this.props.location !== nextProps.location) {

const mapDispatchToProps = {

export default withRouter(connect(null, mapDispatchToProps)(App));

Find more questions by tags React