mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* env for base path * delete base path * redo network type * debug review workflow * update values * update values Co-authored-by: Yuliya Sharafitdinova <[email protected]>
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import appConfig from 'configs/app/config';
|
|
|
|
import { ROUTES } from './routes';
|
|
import type { RouteName } from './routes';
|
|
|
|
const PATH_PARAM_REGEXP = /\/\[(\w+)\]/g;
|
|
|
|
export default function link(
|
|
routeName: RouteName,
|
|
urlParams?: Record<string, Array<string> | string | undefined>,
|
|
queryParams?: Record<string, string>,
|
|
): string {
|
|
const route = ROUTES[routeName];
|
|
if (!route) {
|
|
return '';
|
|
}
|
|
|
|
const path = route.pattern.replace(PATH_PARAM_REGEXP, (_, paramName: string) => {
|
|
let paramValue = urlParams?.[paramName];
|
|
if (Array.isArray(paramValue)) {
|
|
// FIXME we don't have yet params as array, but typescript says that we could
|
|
// dunno know how to manage it, fix me if you find an issue
|
|
paramValue = paramValue.join(',');
|
|
}
|
|
|
|
return paramValue ? `/${ paramValue }` : '';
|
|
});
|
|
|
|
const url = new URL(path, appConfig.baseUrl);
|
|
|
|
queryParams && Object.entries(queryParams).forEach(([ key, value ]) => {
|
|
url.searchParams.append(key, value);
|
|
});
|
|
|
|
return url.pathname;
|
|
}
|