github.com/hernad/nomad@v1.6.112/ui/app/utils/add-to-path.js (about)

     1  /**
     2   * Copyright (c) HashiCorp, Inc.
     3   * SPDX-License-Identifier: MPL-2.0
     4   */
     5  
     6  // Adds a string to the end of a URL path while being mindful of query params
     7  export default function addToPath(url, extension = '', additionalParams) {
     8    const [path, params] = url.split('?');
     9    let newUrl = `${path}${extension}`;
    10  
    11    if (params) {
    12      newUrl += `?${params}`;
    13    }
    14  
    15    if (additionalParams) {
    16      if (params) {
    17        newUrl += `&${additionalParams}`;
    18      } else {
    19        newUrl += `?${additionalParams}`;
    20      }
    21    }
    22  
    23    return newUrl;
    24  }