[WEB-3797] fix: remove leading slash from URL to copy (#6890)
* fix: remove prefix slash if present * chore: make use of URL class to generate a valid URL
This commit is contained in:
parent
27cec64c56
commit
37699362ad
9 changed files with 24 additions and 45 deletions
|
|
@ -86,8 +86,11 @@ export const copyTextToClipboard = async (text: string): Promise<void> => {
|
|||
* await copyUrlToClipboard("issues/123") // copies "https://example.com/issues/123"
|
||||
*/
|
||||
export const copyUrlToClipboard = async (path: string) => {
|
||||
const originUrl = typeof window !== "undefined" && window.location.origin ? window.location.origin : "";
|
||||
await copyTextToClipboard(`${originUrl}/${path}`);
|
||||
// get origin or default to empty string if not in browser
|
||||
const originUrl = typeof window !== "undefined" ? window.location.origin : "";
|
||||
// create URL object and ensure proper path formatting
|
||||
const url = new URL(path, originUrl);
|
||||
await copyTextToClipboard(url.toString());
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue