feat(router): use page <title> when injecting pages, fallback to generated title
This commit is contained in:
@@ -168,6 +168,13 @@
|
||||
const injected = parsed.querySelector("[data-page-content]") ?? parsed.body;
|
||||
main.innerHTML = injected.innerHTML.trim();
|
||||
await injectPageScripts(parsed, response.url);
|
||||
// Update document title from the fetched page if present, otherwise use generated title
|
||||
const pageTitleEl = parsed.querySelector("title");
|
||||
if (pageTitleEl && pageTitleEl.textContent && pageTitleEl.textContent.trim()) {
|
||||
document.title = pageTitleEl.textContent.trim();
|
||||
} else {
|
||||
document.title = routeToTitle(route);
|
||||
}
|
||||
}
|
||||
|
||||
function render(route, { replaceHistory = false } = {}) {
|
||||
@@ -177,7 +184,6 @@
|
||||
.then(() => {
|
||||
setActiveRoute(safeRoute);
|
||||
setCanonicalUrl(safeRoute, replaceHistory);
|
||||
document.title = routeToTitle(safeRoute);
|
||||
window.scrollTo({ top: 0, behavior: "smooth" });
|
||||
})
|
||||
.catch((error) => {
|
||||
|
||||
Reference in New Issue
Block a user