@@ -3,7 +3,7 @@ import React from 'react';
33import PropTypes from 'prop-types' ;
44import classNames from 'classnames' ;
55import { connect } from 'react-redux' ;
6- import { debounce } from 'lodash' ;
6+ import { debounce , isEqual } from 'lodash' ;
77
88import { ThemeProvider } from 'styled-components' ;
99import theme from 'weaveworks-ui-components/lib/theme' ;
@@ -67,6 +67,7 @@ class App extends React.Component {
6767
6868 this . setViewportDimensions = this . setViewportDimensions . bind ( this ) ;
6969 this . handleResize = debounce ( this . setViewportDimensions , VIEWPORT_RESIZE_DEBOUNCE_INTERVAL ) ;
70+ this . handleRouteChange = debounce ( props . onRouteChange , 50 ) ;
7071
7172 this . saveAppRef = this . saveAppRef . bind ( this ) ;
7273 this . onKeyPress = this . onKeyPress . bind ( this ) ;
@@ -105,6 +106,10 @@ class App extends React.Component {
105106 if ( nextProps . disableStoreViewState !== this . props . disableStoreViewState ) {
106107 this . props . dispatch ( setStoreViewState ( ! nextProps . disableStoreViewState ) ) ;
107108 }
109+ // Debounce-notify about the route change if the URL state changes its content.
110+ if ( ! isEqual ( nextProps . urlState , this . props . urlState ) ) {
111+ this . handleRouteChange ( nextProps . urlState ) ;
112+ }
108113 }
109114
110115 onKeyUp ( ev ) {
@@ -241,7 +246,6 @@ class App extends React.Component {
241246 }
242247}
243248
244-
245249function mapStateToProps ( state ) {
246250 return {
247251 currentTopology : state . get ( 'currentTopology' ) ,
@@ -267,13 +271,15 @@ function mapStateToProps(state) {
267271App . propTypes = {
268272 renderTimeTravel : PropTypes . func ,
269273 renderNodeDetailsExtras : PropTypes . func ,
274+ onRouteChange : PropTypes . func ,
270275 monitor : PropTypes . bool ,
271276 disableStoreViewState : PropTypes . bool ,
272277} ;
273278
274279App . defaultProps = {
275280 renderTimeTravel : ( ) => < TimeTravelWrapper /> ,
276281 renderNodeDetailsExtras : ( ) => null ,
282+ onRouteChange : ( ) => null ,
277283 monitor : false ,
278284 disableStoreViewState : false ,
279285} ;
0 commit comments