summaryrefslogtreecommitdiff
path: root/shared/components/src/utils/getStorefrontRoute.ts
blob: 2aaaacec2625553725010c31da17c41cc9f24ca0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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;
}