From 3ffa43c0c976545feb23cd68870a110e124eea3a Mon Sep 17 00:00:00 2001 From: Phillip Kruger Date: Fri, 5 Apr 2024 11:28:06 +1100 Subject: [PATCH] Revert removal of redirec in Dev UI Deep links Signed-off-by: Phillip Kruger --- .../dev-ui/controller/router-controller.js | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/controller/router-controller.js b/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/controller/router-controller.js index cc259a7f67065..a70a2a0efd2e9 100644 --- a/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/controller/router-controller.js +++ b/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/controller/router-controller.js @@ -200,12 +200,47 @@ export class RouterController { RouterController.router.addRoutes(routes); - if(currentSelection === path){ + var currentSelection = window.location.pathname; + const search = this.getQueryParamsWithoutFrom(); + + var relocationRequest = this.getQueryParameter("from"); + if (relocationRequest) { + // We know and already loaded the requested location + if (relocationRequest === path) { + Router.go({pathname: path, search}); + } + } else if(currentSelection === path){ Router.go({pathname: path, search}); - }else if(!RouterController.router.location.route && currentSelection.endsWith('/dev-ui/') && defaultRoute) { + } else if(!RouterController.router.location.route && currentSelection.endsWith('/dev-ui/') && defaultRoute) { Router.go({pathname: path, search}); + // We do not know and have not yet loaded the requested location + } else if (!RouterController.router.location.route && defaultRoute) { + // pass original query param + const currentQueryString = window.location.search; + const origSearch = currentQueryString?.length > 0 ? '&' + currentQueryString : ''; + + Router.go({ + pathname: path, + search: '?from=' + currentSelection + origSearch, + }); + } + } + } + + getQueryParamsWithoutFrom() { + const params = new URLSearchParams(window.location.search); + if (params) { + const paramsWithoutFrom = []; + params.forEach((value, key) => { + if (key !== 'from') { + paramsWithoutFrom.push(key + '=' + value) + } + }); + if (paramsWithoutFrom.length > 0) { + return paramsWithoutFrom.join('&'); } } + return ''; } getQueryParameters() {