@wener/console
Version:
Base console UI toolkit
25 lines (24 loc) • 740 B
JavaScript
import { useMatches } from 'react-router';
export function useRouteTitles(id) {
var matches = useMatches();
if (id) {
var i = matches.findIndex(function(match) {
return match.id === id;
});
if (i < 0) {
return [];
}
matches = matches.slice(0, i + 1);
}
return matches.filter(function(v) {
var _v_handle;
return (_v_handle = v.handle) === null || _v_handle === void 0 ? void 0 : _v_handle.title;
}).map(function(match) {
var data = match.data, handle = match.handle;
var title = handle.title;
if (typeof title === 'function') {
return title(data, match);
}
return String(title);
});
}