Function to get title based on pathname
I'd make an object whose key is the pathname and whose value is the unique string for that pathname, then iterate through the object to find the matching key:


const BASE_SITE_NAME = 'BASE_SITE_NAME';
const descriptions = {
    about: 'About Us',
    fees: 'Our Fees',
    legal: 'Legal Info',
    register: 'Registration',
    login: 'Login',
};
const getMetaDescription = (pathname) =&gt; {
    const foundDescriptionKey = Object.keys(descriptions).find(key =&gt; pathname.includes(key));
    return foundDescriptionKey
        ? descriptions[foundDescriptionKey] + ' | ' + BASE_SITE_NAME
        : BASE_SITE_NAME;
};

console.log(getMetaDescription('about'));
console.log(getMetaDescription('foobar'));



If pathname is directly from the URL in the browser, make sure to call toLowerCase() on it first (just in case, for example, someone types in example.com/ABOUT instead of clicking a link that redirects to /about).
This is faithful to your original code. But if each of the descriptions correspond to an entirely separate route, it'd be better to just use plain property lookup. For example, if the pathname is /about, extract the about from that and look up that key on the object, instead of iterating.


const BASE_SITE_NAME = 'BASE_SITE_NAME';
const descriptions = {
    about: 'About Us',
    fees: 'Our Fees',
    legal: 'Legal Info',
    register: 'Registration',
    login: 'Login',
};
const getMetaDescription = (pathname) =&gt; {
    const description = descriptions[pathname.slice(1)];
    return description
        ? description + ' | ' + BASE_SITE_NAME
        : BASE_SITE_NAME;
};

console.log(getMetaDescription('/about'));
console.log(getMetaDescription('/foobar'));



The .includes approach is needed only if you have multiple pathnames associated with a single description. Even if you have multiple pathnames associated with a single description, consider using startsWith instead - it'll be more precise and less likely to have collisions. For example, if you have example.com/profile/aboutme, the about would result in About Us being displayed, which would not be desirable.


const BASE_SITE_NAME = 'BASE_SITE_NAME';
const descriptions = {
    about: 'About Us',
    fees: 'Our Fees',
    legal: 'Legal Info',
    register: 'Registration',
    login: 'Login',
    profile: 'Profile',
};
const getMetaDescription = (pathname) =&gt; {
    const foundDescriptionKey = Object.keys(descriptions).find(key =&gt; pathname.slice(1).startsWith(key));
    return foundDescriptionKey
        ? descriptions[foundDescriptionKey] + ' | ' + BASE_SITE_NAME
        : BASE_SITE_NAME;
};

console.log(getMetaDescription('/about'));
console.log(getMetaDescription('/profile/aboutme'));
console.log(getMetaDescription('/foobar'));