mirror of
https://github.com/litruv/Docs-Viewer.git
synced 2026-07-25 03:06:07 +10:00
Refactor URL slug handling in NavigationService for cleaner format
This commit is contained in:
7
index.js
7
index.js
@@ -468,8 +468,8 @@ class NavigationService {
|
|||||||
|
|
||||||
setupEventListeners() {
|
setupEventListeners() {
|
||||||
window.addEventListener('popstate', async () => {
|
window.addEventListener('popstate', async () => {
|
||||||
const slug = new URLSearchParams(window.location.search).toString()
|
// Get slug without equal sign and question mark
|
||||||
.replace(/^=/, '').replace(/^\?/, '');
|
const slug = window.location.search.replace(/^\?=?/, '').replace(/^=/, '');
|
||||||
const hash = window.location.hash;
|
const hash = window.location.hash;
|
||||||
this.eventBus.emit('navigation:requested', { slug, hash });
|
this.eventBus.emit('navigation:requested', { slug, hash });
|
||||||
});
|
});
|
||||||
@@ -479,7 +479,8 @@ class NavigationService {
|
|||||||
if (target) {
|
if (target) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const slug = target.href.split('?').pop();
|
const slug = target.href.split('?').pop();
|
||||||
history.pushState({ slug }, '', target.href);
|
// Use clean URL format without equal sign
|
||||||
|
history.pushState(null, '', `?${slug}`);
|
||||||
this.eventBus.emit('navigation:requested', { slug });
|
this.eventBus.emit('navigation:requested', { slug });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user