@@ -39,7 +39,8 @@ export interface initParams {
3939 ctx : any ,
4040 errors : any ,
4141 isUniversal : boolean ,
42- helpers ?: any
42+ helpers ?: any ,
43+ isCaseInsesitive ?: boolean
4344}
4445export interface initResult {
4546 Router ?: any ,
@@ -78,17 +79,24 @@ export default class Router extends React.Component<Props, State> {
7879 this . subscriber = null ;
7980 }
8081 static async init ( opts : initParams ) : Promise < initResult > {
81- const { routes, hooks, history = null , ctx = new Context ( ) , errors, isUniversal, helpers } = opts ;
82+ const { routes, hooks, history = null , ctx = new Context ( ) , errors, isUniversal, helpers, isCaseInsesitive = false } = opts ;
8283 let { path } = opts ;
83- path = path . replace ( this . clearSlashesRegex , '/' ) ;
8484 let plainRoutes ;
85+
86+ path = path . replace ( this . clearSlashesRegex , '/' ) ;
87+
8588 if ( ( Array . isArray ( routes ) && React . isValidElement ( routes [ 0 ] ) ) || React . isValidElement ( routes ) ) {
8689 plainRoutes = Router . buildRoutes ( routes ) ;
8790 } else {
8891 plainRoutes = routes ;
8992 }
93+
9094 const router = new RouterAsync ( { routes : plainRoutes , hooks, helpers } ) ;
9195
96+ if ( isCaseInsesitive ) {
97+ path = this . caseInsesitive ( path , router . routes ) ;
98+ }
99+
92100 let routerResult : any = { } ;
93101 let callback = ( ) => { /* noop */ } ;
94102 if ( isUniversal ) {
@@ -133,6 +141,21 @@ export default class Router extends React.Component<Props, State> {
133141 error
134142 }
135143 }
144+ static caseInsesitive ( path , routes ) {
145+ for ( const route of routes ) {
146+ if ( typeof route . path === 'object' ) {
147+ if ( route . pattern . exec ( path . toLowerCase ( ) ) ) {
148+ return path . toLowerCase ( ) ;
149+ }
150+ } else {
151+ if ( route . path . toLowerCase ( ) === path . toLowerCase ( ) || route . pattern . exec ( path ) ) {
152+ return route . path ;
153+ }
154+ }
155+ }
156+
157+ return path ;
158+ }
136159 static buildRoutes ( routes ) {
137160 if ( ! Array . isArray ( routes ) ) routes = routes . props . children ;
138161 return deepMap ( routes , route => {
0 commit comments