Skip to content

Commit

Permalink
Keep query params for extension page deeplinks
Browse files Browse the repository at this point in the history
  • Loading branch information
michalvavrik authored and manofthepeace committed May 16, 2023
1 parent ffb3f0f commit 4ce7d88
Showing 1 changed file with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,31 +156,52 @@ export class RouterController {
}

var currentSelection = window.location.pathname;
var currentQueryString = window.location.search;
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});
Router.go({pathname: path, search});
}
} else {
// We know and already loaded the requested location
if (currentSelection === path) {
Router.go({pathname: path});
Router.go({pathname: path, search});
// The default naked route
} else if (!RouterController.router.location.route && defaultRoute && currentSelection.endsWith('/dev-ui/')) {
Router.go({pathname: path});
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,
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() {
const params = new Proxy(new URLSearchParams(window.location.search), {
get: (searchParams, prop) => searchParams.get(prop),
Expand Down

0 comments on commit 4ce7d88

Please sign in to comment.