Skip to content

Commit 52546f1

Browse files
authored
fix: fix createExternalUILink (#571)
1 parent b12dceb commit 52546f1

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/routes.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff 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+
2845
export type Query = Record<string | number, string | number | string[] | number[] | undefined>;
2946

3047
export 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)

0 commit comments

Comments
 (0)