open-nomad/ui/app/utils/add-to-path.js
2023-04-10 15:36:59 +00:00

17 lines
361 B
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
// Adds a string to the end of a URL path while being mindful of query params
export default function addToPath(url, extension = '') {
const [path, params] = url.split('?');
let newUrl = `${path}${extension}`;
if (params) {
newUrl += `?${params}`;
}
return newUrl;
}