Skip to content

Commit fc19cca

Browse files
author
Andrea Barbasso
committed
[DSC-1742] remove language queryParam when locale is resolved
1 parent 1b19d0f commit fc19cca

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

src/app/core/locale/locale.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export class LocaleService {
5353
this.routeService.getQueryParameterValue('lang').subscribe(lang => {
5454
if (lang && this.translate.getLangs().includes(lang)) {
5555
this.setCurrentLanguageCode(lang);
56+
this.routeService.removeQueryParam('lang');
5657
}
5758
});
5859
}

src/app/core/services/route.service.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,23 @@ export class RouteService {
225225
}
226226
);
227227
}
228+
229+
/**
230+
* Remove a parameter from the current route
231+
* @param key The parameter name
232+
*/
233+
removeQueryParam(key: string) {
234+
let queryParams = { ...this.route.snapshot.queryParams };
235+
delete queryParams[key];
236+
237+
// Navigate to the same route with the updated queryParams
238+
this.router.navigate(
239+
[],
240+
{
241+
relativeTo: this.route,
242+
queryParams: queryParams,
243+
}
244+
);
245+
246+
}
228247
}

src/app/shared/testing/route-service.stub.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ export const routeServiceStub: any = {
3737
},
3838
getPreviousUrl: () => {
3939
return observableOf('/home');
40+
},
41+
removeQueryParam: () => {
42+
return;
4043
}
4144
/* eslint-enable no-empty, @typescript-eslint/no-empty-function */
4245
};

0 commit comments

Comments
 (0)