diff --git a/packages/sui-react-router/src/Router.js b/packages/sui-react-router/src/Router.js index 6ef428f3b..d0a055e2a 100644 --- a/packages/sui-react-router/src/Router.js +++ b/packages/sui-react-router/src/Router.js @@ -65,7 +65,7 @@ const Router = ({ const [state, setState] = useState({router, params, components}) useEffect(() => { - let prevState = {} + let prevState = null const handleTransition = (err, nextState) => { if (err) { if (onError) return onError(err) @@ -73,8 +73,17 @@ const Router = ({ } // avoid not needed re-renders of the state if the prevState and the nextState - // are the same reference - if (prevState === nextState) return + // are the same reference or if the first render + + if (!prevState) { + prevState = nextState + return + } + + if (prevState === nextState) { + return + } + prevState = nextState const {components, params, location, routes} = nextState