File tree 3 files changed +24
-19
lines changed
3 files changed +24
-19
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " react-router-dom " : patch
3
+ " @remix-run/router " : patch
4
+ ---
5
+
6
+ Fix navigation for hash routers on manual URL changes
Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ export interface Update {
85
85
/**
86
86
* The delta between this location and the former location in the history stack
87
87
*/
88
- delta : number ;
88
+ delta : number | null ;
89
89
}
90
90
91
91
/**
@@ -612,24 +612,12 @@ function getUrlBasedHistory(
612
612
}
613
613
614
614
function handlePop ( ) {
615
- let nextAction = Action . Pop ;
615
+ action = Action . Pop ;
616
616
let nextIndex = getIndex ( ) ;
617
-
618
- if ( nextIndex != null ) {
619
- let delta = nextIndex - index ;
620
- action = nextAction ;
621
- index = nextIndex ;
622
- if ( listener ) {
623
- listener ( { action, location : history . location , delta } ) ;
624
- }
625
- } else {
626
- warning (
627
- false ,
628
- `You are trying to perform a POP navigation to a location that was not ` +
629
- `created by @remix-run/router. This will fail silently in production. ` +
630
- `You should navigate via the router to avoid this situation (instead of ` +
631
- `using window.history.pushState/window.location.hash).`
632
- ) ;
617
+ let delta = nextIndex == null ? null : nextIndex - index ;
618
+ index = nextIndex ;
619
+ if ( listener ) {
620
+ listener ( { action, location : history . location , delta } ) ;
633
621
}
634
622
}
635
623
Original file line number Diff line number Diff line change @@ -781,12 +781,23 @@ export function createRouter(init: RouterInit): Router {
781
781
return ;
782
782
}
783
783
784
+ warning (
785
+ activeBlocker != null && delta === null ,
786
+ "You are trying to use a blocker on a POP navigation to a location " +
787
+ "that was not created by @remix-run/router. This will fail silently in " +
788
+ "production. This can happen if you are navigating outside the router " +
789
+ "via `window.history.pushState`/`window.location.hash` instead of using " +
790
+ "router navigation APIs. This can also happen if you are using " +
791
+ "createHashRouter and the user manually changes the URL."
792
+ ) ;
793
+
784
794
let blockerKey = shouldBlockNavigation ( {
785
795
currentLocation : state . location ,
786
796
nextLocation : location ,
787
797
historyAction,
788
798
} ) ;
789
- if ( blockerKey ) {
799
+
800
+ if ( blockerKey && delta != null ) {
790
801
// Restore the URL to match the current UI, but don't update router state
791
802
ignoreNextHistoryUpdate = true ;
792
803
init . history . go ( delta * - 1 ) ;
You can’t perform that action at this time.
0 commit comments