File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed
Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -931,7 +931,27 @@ export interface RouteURLProps {
931931
932932export function createRouteURL ( routeName : string , params : RouteURLProps = { } ) {
933933 const storeRoutes = store . getState ( ) . routes . routes ;
934- const route = ( storeRoutes && storeRoutes [ routeName ] ) || getRoute ( routeName ) ;
934+
935+ // First try to find by name
936+ const matchingStoredRouteByName =
937+ storeRoutes &&
938+ Object . entries ( storeRoutes ) . find (
939+ ( [ , route ] ) => route . name ?. toLowerCase ( ) === routeName . toLowerCase ( )
940+ ) ?. [ 1 ] ;
941+
942+ // Then try to find by path
943+ const matchingStoredRouteByPath =
944+ storeRoutes &&
945+ Object . entries ( storeRoutes ) . find ( ( [ key ] ) => key . toLowerCase ( ) === routeName . toLowerCase ( ) ) ?. [ 1 ] ;
946+
947+ if ( matchingStoredRouteByPath && ! matchingStoredRouteByName ) {
948+ console . warn (
949+ `[Deprecation] Route "${ routeName } " was found by path instead of name. ` +
950+ 'Please use route names instead of paths when calling createRouteURL.'
951+ ) ;
952+ }
953+
954+ const route = matchingStoredRouteByName || matchingStoredRouteByPath || getRoute ( routeName ) ;
935955
936956 if ( ! route ) {
937957 return '' ;
You can’t perform that action at this time.
0 commit comments