[Library | Trunk]: Fix reload for urls with fragments

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@60630 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2021-03-11 17:40:25 +00:00
parent 39cd5682c9
commit 1042733054
1 changed files with 19 additions and 6 deletions

View File

@ -16,20 +16,33 @@ export class ReloadComponent {
public ngOnInit() {
HelperFunctions.scroll();
var URL = Session.getReloadUrl();
let URL = Session.getReloadUrl();
if (URL && URL["path"] && URL["path"] != null && URL["path"] != "") {
var url = URL["path"];
var host = URL["host"];
var paramsObject = ((URL["params"] && URL["params"] != null) ? Session.getParamsObj(URL["params"]) : null);
let url: string = URL["path"];
let host = URL["host"];
let paramsObject = ((URL["params"] && URL["params"] != null) ? Session.getParamsObj(URL["params"]) : null);
let hash = url.indexOf("#");
if (host == (location.protocol + "//" + location.host)) {
let fragment = (hash !== -1)?url.slice(hash + 1):null;
if(fragment) {
url = url.slice(0, hash);
}
let baseUrl = (document && document.getElementsByTagName('base')) ? document.getElementsByTagName('base')[0].href.split(document.location.host)[1] : "/";
url = (baseUrl.length > 1 && url.indexOf(baseUrl) != -1) ? ("/" + url.split(baseUrl)[1]) : url;
if (paramsObject) {
Session.setReloadUrl("", "", "")
this._router.navigate([url], {queryParams: paramsObject});
if(fragment) {
this._router.navigate([url], {queryParams: paramsObject, fragment: fragment});
} else {
this._router.navigate([url], {queryParams: paramsObject});
}
} else {
Session.setReloadUrl("", "", "")
this._router.navigate([url]);
if(fragment) {
this._router.navigate([url], {fragment: fragment});
} else {
this._router.navigate([url]);
}
}
} else {
Session.setReloadUrl("", "", "")