Extracts the slug from a given URL.
A slug is typically the last part of a URL path, which is used to identify a particular page or resource. This function splits the URL by '/' and returns the last non-empty segment.
The URL string from which to extract the slug.
The extracted slug from the URL.
const slug = getUrlSlug('https://example.com/path/to/resource/');console.log(slug); // Output: 'resource'const slug2 = getUrlSlug('https://example.com/path/to/resource');console.log(slug2); // Output: 'resource' Copy
const slug = getUrlSlug('https://example.com/path/to/resource/');console.log(slug); // Output: 'resource'const slug2 = getUrlSlug('https://example.com/path/to/resource');console.log(slug2); // Output: 'resource'
Extracts the slug from a given URL.
A slug is typically the last part of a URL path, which is used to identify a particular page or resource. This function splits the URL by '/' and returns the last non-empty segment.