@wener/console
Version:
Base console UI toolkit
21 lines (20 loc) • 610 B
JavaScript
import { useMatches } from "react-router-dom";
export function useRouteTitles(id) {
let matches = useMatches();
if (id) {
const i = matches.findIndex((match)=>match.id === id);
if (i < 0) {
return [];
}
matches = matches.slice(0, i + 1);
}
return matches.filter((v)=>v.handle?.title).map((match)=>{
const { data, handle } = match;
const title = handle.title;
if (typeof title === 'function') {
return title(data, match);
}
return String(title);
});
}
//# sourceMappingURL=useRouteTitles.js.map