pagename.js

import { useLocation } from 'react-router';

export default function getPageName() {
  const { pathname } = useLocation();
  const paths = pathname.split('/');
  return paths[1] || 'home';
}