File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ " mobx-route " : minor
3+ ---
4+
5+ added ` fallbackPath ` parameter for cases when ` path-to-regexp ` thrown an error
Original file line number Diff line number Diff line change 1+ ---
2+ " mobx-route " : minor
3+ ---
4+
5+ safe building route urls using ` path-to-regexp ` lib
Original file line number Diff line number Diff line change @@ -8,4 +8,5 @@ export interface RouteGlobalConfig {
88 mergeQuery ?: boolean ;
99 createUrl ?: UrlCreateParamsFn ;
1010 formatLinkHref ?: ( href : string ) => string ;
11+ fallbackPath ?: string ;
1112}
Original file line number Diff line number Diff line change @@ -343,7 +343,14 @@ export class Route<
343343 routeConfig . get ( ) . createUrl ?.( defaultUrlCreateParams , this . query . data ) ??
344344 defaultUrlCreateParams ;
345345
346- const path = this . _compiler ( this . processParams ( urlCreateParams . params ) ) ;
346+ let path : string ;
347+
348+ try {
349+ path = this . _compiler ( this . processParams ( urlCreateParams . params ) ) ;
350+ } catch ( e ) {
351+ console . error ( 'Error while compiling route path' , e ) ;
352+ path = this . config . fallbackPath ?? routeConfig . get ( ) . fallbackPath ?? '/' ;
353+ }
347354
348355 const url = `${ urlCreateParams . baseUrl || '' } ${ this . isHash ? '#' : '' } ${ path } ` ;
349356
You can’t perform that action at this time.
0 commit comments