@@ -87,14 +87,14 @@ export function LocationProvider(props) {
87
87
}
88
88
89
89
const RESOLVED = Promise . resolve ( ) ;
90
-
91
90
export function Router ( props ) {
92
- const [ , update ] = useReducer ( c => c + 1 , 0 ) ;
91
+ const [ c , update ] = useReducer ( c => c + 1 , 0 ) ;
93
92
94
93
const { url, query, wasPush, path } = useLocation ( ) ;
95
94
const { rest = path , params = { } } = useContext ( RouteContext ) ;
96
95
97
96
const isLoading = useRef ( false ) ;
97
+ const prevRoute = useRef ( path ) ;
98
98
// Monotonic counter used to check if an un-suspending route is still the current route:
99
99
const count = useRef ( 0 ) ;
100
100
// The current route:
@@ -177,10 +177,14 @@ export function Router(props) {
177
177
hasEverCommitted . current = true ;
178
178
179
179
// The route is loaded and rendered.
180
- if ( wasPush ) scrollTo ( 0 , 0 ) ;
181
- if ( props . onLoadEnd && isLoading . current ) props . onLoadEnd ( url ) ;
182
- isLoading . current = false ;
183
- } ) ;
180
+ if ( prevRoute . current !== path ) {
181
+ if ( wasPush ) scrollTo ( 0 , 0 ) ;
182
+ if ( props . onLoadEnd && isLoading . current ) props . onLoadEnd ( url ) ;
183
+ if ( props . onRouteChange && ! isLoading . current ) props . onRouteChange ( url ) ;
184
+ isLoading . current = false ;
185
+ prevRoute . current = path ;
186
+ }
187
+ } , [ path , wasPush , c ] ) ;
184
188
185
189
// Note: curChildren MUST render first in order to set didSuspend & prev.
186
190
return [ h ( RenderRef , { r : cur } ) , h ( RenderRef , { r : prev } ) ] ;
0 commit comments