File tree 2 files changed +7
-6
lines changed
2 files changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ var React = require('react');
6
6
var cloneWithProps = require ( 'react/lib/cloneWithProps' ) ;
7
7
var assign = Object . assign || require ( 'object.assign' ) ;
8
8
9
+ var patternCache = { } ;
10
+
9
11
/**
10
12
* Match routes against a path
11
13
*
@@ -33,9 +35,12 @@ function matchRoutes(routes, path) {
33
35
}
34
36
35
37
if ( current . props . path ) {
36
- current . props . pattern = current . props . pattern || new URLPattern ( current . props . path , createCompiler ( current . props ) ) ;
38
+ // Technically, this cache will incorrectly be used if a user defines two routes
39
+ // with identical paths but different compilers. FIXME?
40
+ var pattern = patternCache [ current . props . path ] ||
41
+ new URLPattern ( current . props . path , createCompiler ( current . props ) ) ;
37
42
if ( ! page ) {
38
- match = current . props . pattern . match ( path ) ;
43
+ match = pattern . match ( path ) ;
39
44
if ( match ) {
40
45
page = current ;
41
46
}
Original file line number Diff line number Diff line change @@ -20,10 +20,6 @@ describe('matchRoutes', function() {
20
20
] ;
21
21
22
22
afterEach ( function ( ) {
23
- // Remove any compiled regex patterns from all routes
24
- routes . forEach ( function ( r ) {
25
- r . props . pattern = null ;
26
- } ) ;
27
23
// In case we overrode this, reset it.
28
24
Router . createURLPatternCompiler = function ( ) { return new URLPattern . Compiler ( ) ; } ;
29
25
} ) ;
You can’t perform that action at this time.
0 commit comments