FWIW, вы можете использовать history.createHref (), чтобы применить базовое имя к URL-адресу, созданному с помощью generatePath, или любым другим способом:
const pathname = generatePath(routeUrl, params);
const url = history.createHref({
pathname
});
// url includes basename
Так что я решил это следующим образом
App.js
<BrowserRouter basename="/defaultPathname">
{children}
</BrowserRouter>
Component.js
const Component = ({ match, history, children, linkId }) => {
const pathname = useMemo(() => generatePath(`${match.path}/${linkId}`), [linkId, match.path])
const newLink = history.createHref({ pathname })
return (
<a
href={newLink}
onClick={(e) => {
e.preventDefault()
history.push({
pathname,
})
}}
>
{children}
</a>
)
}