Стрелка «назад» в каналах шагает по истории, а не по кругу

Ответ → запись → канал → список каналов: если на страницу пришли из канала
или обсуждения, «назад» возвращает по истории. Раньше повторный переход
гонял по кругу запись и открытый из неё ответ.
This commit is contained in:
q
2026-10-12 12:11:35 +03:00
parent 3edde418a2
commit 68fe0532ce
5 changed files with 24 additions and 22 deletions
+16 -3
View File
@@ -462,12 +462,14 @@ export function getRoute() {
export function navigate(path) {
const cleanPath = toPrettyPath(path);
const nextPath = cleanPath ? `/${cleanPath}` : '/';
if (window.location.pathname !== nextPath) {
const fromPath = window.location.pathname;
if (fromPath !== nextPath) {
previousTrackedPath = currentTrackedPath;
currentTrackedPath = nextPath;
}
if (window.location.pathname !== nextPath) {
window.history.pushState({}, '', nextPath);
if (fromPath !== nextPath) {
// Запись помнит, откуда на неё пришли: «назад» в шапке может вернуться по истории, а не открывать страницу заново.
window.history.pushState({ shineFrom: fromPath }, '', nextPath);
}
window.dispatchEvent(new PopStateEvent('popstate'));
}
@@ -517,6 +519,17 @@ export function toPrettyPath(path) {
return [prettyHead, ...tail].join('/');
}
// Стрелка «назад» в шапке: если сюда пришли со страницы, которую isParent признаёт своей, – шаг по истории
// (как стек: ответ → запись → канал), иначе переход на fallback. Повторный navigate гонял бы по кругу две страницы.
export function navigateUp(isParent, fallback) {
const from = String(window.history.state?.shineFrom || '');
if (from && isParent(parseRouteFromPath(from), from)) {
window.history.back();
return;
}
navigate(fallback);
}
export function navigateBack() {
if (window.history.length <= 1) return;
window.history.back();