File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,23 @@ export const parseQuery = (location: Location) => {
2525 } ) ;
2626} ;
2727
28+ const prepareRoute = ( route : string ) => {
29+ let preparedRoute = route ;
30+ const portRegExp = / : \d { 3 , 5 } / g;
31+ const portMatch = route . match ( portRegExp ) ;
32+
33+ // if port exists in route we escape port to avoid errors in function compile()
34+ // compile(preparedRoute) parses prepared root by symbol ":"
35+ // if we pass raw route and there is a port in route, compile()
36+ // will try to parse the port and throw an error
37+ if ( portMatch ) {
38+ const port = portMatch [ 0 ] ;
39+ preparedRoute = route . replace ( portRegExp , ':\\' + port . slice ( 1 ) ) ;
40+ }
41+
42+ return preparedRoute ;
43+ } ;
44+
2845export type Query = Record < string | number , string | number | string [ ] | number [ ] | undefined > ;
2946
3047export function createHref (
@@ -46,7 +63,9 @@ export function createHref(
4663
4764 const search = isEmpty ( extendedQuery ) ? '' : `?${ qs . stringify ( extendedQuery , { encode : false } ) } ` ;
4865
49- return `${ compile ( route ) ( params ) } ${ search } ` ;
66+ const preparedRoute = prepareRoute ( route ) ;
67+
68+ return `${ compile ( preparedRoute ) ( params ) } ${ search } ` ;
5069}
5170
5271// embedded version could be located in some folder (e.g. host/some_folder/app_router_path)
You can’t perform that action at this time.
0 commit comments