diff options
| author | rxliuli <rxliuli@gmail.com> | 2025-11-04 05:03:50 +0800 |
|---|---|---|
| committer | rxliuli <rxliuli@gmail.com> | 2025-11-04 05:03:50 +0800 |
| commit | bce557cc2dc767628bed6aac87301a1be7c5431b (patch) | |
| tree | b51a051228d01fe3306cd7626d4a96768aadb944 /shared/components/src/utils/getStorefrontRoute.ts | |
init commit
Diffstat (limited to 'shared/components/src/utils/getStorefrontRoute.ts')
| -rw-r--r-- | shared/components/src/utils/getStorefrontRoute.ts | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/shared/components/src/utils/getStorefrontRoute.ts b/shared/components/src/utils/getStorefrontRoute.ts new file mode 100644 index 0000000..2aaaace --- /dev/null +++ b/shared/components/src/utils/getStorefrontRoute.ts @@ -0,0 +1,29 @@ +/** + * Defines a route based on a given default route and + * otherwise falls back to the base storefront path + * + * @param defaultRoute - ie 'browse', 'listen-now', or empty string + * @param storefront - storefront id ie 'us' + * @param language - language tag ie 'en-US' + * @returns route - ie /us/browse?l=es-MX + */ +export function getStorefrontRoute( + defaultRoute: string, + storefront: string, + language?: string, +): string { + let route; + + if (defaultRoute === '') { + route = `/${storefront}`; + } else { + route = `/${storefront}/${defaultRoute}`; + } + + // add optional language tag if that is passed in + if (language) { + route = `${route}?l=${language}`; + } + + return route; +} |
