fix(): Fix logic regarding other queryparams

This commit is contained in:
Depickere Sven 2023-03-08 16:56:52 +01:00
parent c3cee7d28b
commit ba7b51b7c9

View File

@ -30,7 +30,11 @@ export class HistoryService {
if (!id) { if (!id) {
return ''; return '';
} }
return this.getHrefSplitCharacter() + id; if (this.shouldQueryParamNavigationBeUsed()) {
return this.getFullUrl(id);
} else {
return '#' + id;
}
} }
subscribe(cb): () => void { subscribe(cb): () => void {
@ -65,19 +69,23 @@ export class HistoryService {
return; return;
} }
if (rewriteHistory) { if (rewriteHistory) {
window.history.replaceState( if (this.shouldQueryParamNavigationBeUsed()) {
null, window.history.replaceState(null, '', this.getFullUrl(id));
'', } else {
window.location.href.split(this.getHrefSplitCharacter())[0] + this.linkForId(id), window.history.replaceState(
); null,
'',
window.location.href.split('#')[0] + this.linkForId(id),
);
}
return; return;
} }
window.history.pushState( if (this.shouldQueryParamNavigationBeUsed()) {
null, window.history.pushState(null, '', this.getFullUrl(id));
'', } else {
window.location.href.split(this.getHrefSplitCharacter())[0] + this.linkForId(id), window.history.pushState(null, '', window.location.href.split('#')[0] + this.linkForId(id));
); }
this.emit(); this.emit();
} }
@ -93,7 +101,19 @@ export class HistoryService {
return ''; return '';
} }
private getHrefSplitCharacter(): string { private getFullUrl(id: string): string {
return this.shouldQueryParamNavigationBeUsed() ? '?redoc=' : '#'; const url = this.getUrl();
url.searchParams.set('redoc', id);
return url.toString();
} }
private getUrl(): URL {
return new URL(window.location.href);
}
// private getQueryParamKey(): void {
// let searchParams = new URLSearchParams(window.location.search);
// searchParams.get('redoc')
//
// }
} }