[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,21 +16,34 @@ export class ReloadComponent {
public ngOnInit() { public ngOnInit() {
HelperFunctions.scroll(); HelperFunctions.scroll();
var URL = Session.getReloadUrl(); let URL = Session.getReloadUrl();
if (URL && URL["path"] && URL["path"] != null && URL["path"] != "") { if (URL && URL["path"] && URL["path"] != null && URL["path"] != "") {
var url = URL["path"]; let url: string = URL["path"];
var host = URL["host"]; let host = URL["host"];
var paramsObject = ((URL["params"] && URL["params"] != null) ? Session.getParamsObj(URL["params"]) : null); let paramsObject = ((URL["params"] && URL["params"] != null) ? Session.getParamsObj(URL["params"]) : null);
let hash = url.indexOf("#");
if (host == (location.protocol + "//" + location.host)) { 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] : "/"; 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; url = (baseUrl.length > 1 && url.indexOf(baseUrl) != -1) ? ("/" + url.split(baseUrl)[1]) : url;
if (paramsObject) { if (paramsObject) {
Session.setReloadUrl("", "", "") Session.setReloadUrl("", "", "")
if(fragment) {
this._router.navigate([url], {queryParams: paramsObject, fragment: fragment});
} else {
this._router.navigate([url], {queryParams: paramsObject}); this._router.navigate([url], {queryParams: paramsObject});
}
} else { } else {
Session.setReloadUrl("", "", "") Session.setReloadUrl("", "", "")
if(fragment) {
this._router.navigate([url], {fragment: fragment});
} else {
this._router.navigate([url]); this._router.navigate([url]);
} }
}
} else { } else {
Session.setReloadUrl("", "", "") Session.setReloadUrl("", "", "")
window.location.href = host + url + ((URL["params"] && URL["params"] != null) ? ((URL["params"].indexOf("?") == -1 ? "?" : "") + URL["params"]) : ""); window.location.href = host + url + ((URL["params"] && URL["params"] != null) ? ((URL["params"].indexOf("?") == -1 ? "?" : "") + URL["params"]) : "");