UI: переход на history-router без # и короткие ссылки тредов

This commit is contained in:
AidarKC
2026-05-19 10:15:15 +03:00
parent 3a0899bcfe
commit db2d9a666b
9 changed files with 61 additions and 28 deletions
+19 -9
View File
@@ -14,7 +14,12 @@ export const PRE_AUTH_PAGES = [
];
export function getRoute() {
const raw = window.location.hash.replace(/^#\/?/, '');
const currentPath = String(window.location.pathname || '').trim();
const raw = currentPath
.replace(/^\/+/, '')
.replace(/^index\.html$/i, '')
.replace(/^index\.html\//i, '')
.replace(/\/+$/, '');
if (!raw) {
return { pageId: '', params: {} };
}
@@ -52,8 +57,8 @@ export function getRoute() {
if (pageId === 'channel') {
// Короткий формат:
// #/channel/{ownerBlockchainName}/{channelName}
// #/channel/{ownerBlockchainName}/{channelName}/{messageBlockNumber}
// /channel/{ownerBlockchainName}/{channelName}
// /channel/{ownerBlockchainName}/{channelName}/{messageBlockNumber}
const ownerBlockchainName = decodePart(segments[1] || '');
const channelName = decodePart(segments[2] || '');
const messageBlockNumber = segments[3] || '';
@@ -91,10 +96,10 @@ export function getRoute() {
params: {
messageBlockchainName: decodePart(segments[1]),
messageBlockNumber: segments[2] || '',
messageBlockHash: segments[3] || '',
channelOwnerBlockchainName: decodePart(segments[4]),
channelRootBlockNumber: segments[5] || '',
channelRootBlockHash: segments[6] || '',
messageBlockHash: '',
channelOwnerBlockchainName: decodePart(segments[3]),
channelRootBlockNumber: segments[4] || '',
channelRootBlockHash: segments[5] || '',
},
};
}
@@ -105,7 +110,7 @@ export function getRoute() {
params: {
messageBlockchainName: decodePart(segments[1]),
messageBlockNumber: segments[2] || '',
messageBlockHash: segments[3] || '',
messageBlockHash: '',
channelOwnerBlockchainName: '',
channelRootBlockNumber: '',
channelRootBlockHash: '',
@@ -149,7 +154,12 @@ export function getRoute() {
}
export function navigate(path) {
window.location.hash = `#/${path}`;
const cleanPath = String(path || '').replace(/^\/+/, '');
const nextPath = cleanPath ? `/${cleanPath}` : '/';
if (window.location.pathname !== nextPath) {
window.history.pushState({}, '', nextPath);
}
window.dispatchEvent(new PopStateEvent('popstate'));
}
export function resolveToolbarActive(pageId) {