SHA256
UI: переход на history-router без # и короткие ссылки тредов
This commit is contained in:
+19
-9
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user