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) {
return '';
}
return this.getHrefSplitCharacter() + id;
if (this.shouldQueryParamNavigationBeUsed()) {
return this.getFullUrl(id);
} else {
return '#' + id;
}
}
subscribe(cb): () => void {
@ -65,19 +69,23 @@ export class HistoryService {
return;
}
if (rewriteHistory) {
window.history.replaceState(
null,
'',
window.location.href.split(this.getHrefSplitCharacter())[0] + this.linkForId(id),
);
if (this.shouldQueryParamNavigationBeUsed()) {
window.history.replaceState(null, '', this.getFullUrl(id));
} else {
window.history.replaceState(
null,
'',
window.location.href.split('#')[0] + this.linkForId(id),
);
}
return;
}
window.history.pushState(
null,
'',
window.location.href.split(this.getHrefSplitCharacter())[0] + this.linkForId(id),
);
if (this.shouldQueryParamNavigationBeUsed()) {
window.history.pushState(null, '', this.getFullUrl(id));
} else {
window.history.pushState(null, '', window.location.href.split('#')[0] + this.linkForId(id));
}
this.emit();
}
@ -93,7 +101,19 @@ export class HistoryService {
return '';
}
private getHrefSplitCharacter(): string {
return this.shouldQueryParamNavigationBeUsed() ? '?redoc=' : '#';
private getFullUrl(id: string): string {
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')
//
// }
}