1
+ import warning from 'warning' ;
1
2
import useQueries from 'history/lib/useQueries' ;
2
3
import computeChangedRoutes from './computeChangedRoutes' ;
3
4
import { runEnterHooks , runLeaveHooks } from './TransitionUtils' ;
@@ -24,6 +25,20 @@ function useRoutes(createHistory) {
24
25
return _isActive ( pathname , query , state . location , state . routes , state . params ) ;
25
26
}
26
27
28
+ function matchRoutesWithWarning ( routes , location , callback ) {
29
+ matchRoutes ( routes , location , function ( error , nextState ) {
30
+ if ( error || nextState ) {
31
+ callback ( error , nextState ) ;
32
+ } else {
33
+ warning (
34
+ false ,
35
+ 'Location "%s" did not match any routes' ,
36
+ location . pathname + location . search
37
+ ) ;
38
+ }
39
+ } ) ;
40
+ }
41
+
27
42
// TODO: If we had a way to uniquely identify a route,
28
43
// we could use a plain object here instead...
29
44
var routeHooks = new Map ( ) ;
@@ -34,7 +49,7 @@ function useRoutes(createHistory) {
34
49
// Continue from where we left off.
35
50
finishMatch ( partialNextState , callback ) ;
36
51
} else {
37
- matchRoutes ( routes , location , function ( error , nextState ) {
52
+ matchRoutesWithWarning ( routes , location , function ( error , nextState ) {
38
53
if ( error ) {
39
54
callback ( error ) ;
40
55
} else {
@@ -78,7 +93,7 @@ function useRoutes(createHistory) {
78
93
}
79
94
80
95
function transitionHook ( location , callback ) {
81
- matchRoutes ( routes , location , function ( error , nextState ) {
96
+ matchRoutesWithWarning ( routes , location , function ( error , nextState ) {
82
97
if ( error ) {
83
98
// TODO: Handle the error.
84
99
callback ( false ) ; // Cancel the transition.
0 commit comments