MOBILE-3636 core: Check route parent params on navigator
parent
22395607ae
commit
b0cf681ab6
|
@ -243,12 +243,34 @@ export class CoreNavigatorService {
|
||||||
return CoreUrlUtils.instance.removeUrlParams(this.previousPath || '');
|
return CoreUrlUtils.instance.removeUrlParams(this.previousPath || '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterately get the params checking parent routes.
|
||||||
|
*
|
||||||
|
* @param route Current route.
|
||||||
|
* @param name Name of the parameter.
|
||||||
|
* @return Value of the parameter, undefined if not found.
|
||||||
|
*/
|
||||||
|
protected getRouteSnapshotParam<T = unknown>(name: string, route?: ActivatedRoute): T | undefined {
|
||||||
|
if (!route?.snapshot) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const value = route.snapshot.queryParams[name] ?? route.snapshot.params[name];
|
||||||
|
|
||||||
|
if (typeof value != 'undefined') {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.getRouteSnapshotParam(name, route.parent || undefined);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a parameter for the current route.
|
* Get a parameter for the current route.
|
||||||
* Please notice that objects can only be retrieved once. You must call this function only once per page and parameter,
|
* Please notice that objects can only be retrieved once. You must call this function only once per page and parameter,
|
||||||
* unless there's a new navigation to the page.
|
* unless there's a new navigation to the page.
|
||||||
*
|
*
|
||||||
* @param name Name of the parameter.
|
* @param name Name of the parameter.
|
||||||
|
* @param params Optional params to get the value from. If missing, it will autodetect.
|
||||||
* @return Value of the parameter, undefined if not found.
|
* @return Value of the parameter, undefined if not found.
|
||||||
*/
|
*/
|
||||||
getRouteParam<T = unknown>(name: string, params?: Params): T | undefined {
|
getRouteParam<T = unknown>(name: string, params?: Params): T | undefined {
|
||||||
|
@ -256,15 +278,16 @@ export class CoreNavigatorService {
|
||||||
|
|
||||||
if (!params) {
|
if (!params) {
|
||||||
const route = this.getCurrentRoute();
|
const route = this.getCurrentRoute();
|
||||||
if (!route.snapshot) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
value = route.snapshot.queryParams[name] ?? route.snapshot.params[name];
|
value = this.getRouteSnapshotParam(name, route);
|
||||||
} else {
|
} else {
|
||||||
value = params[name];
|
value = params[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof value == 'undefined') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let storedParam = this.storedParams[value];
|
let storedParam = this.storedParams[value];
|
||||||
|
|
||||||
// Remove the parameter from our map if it's in there.
|
// Remove the parameter from our map if it's in there.
|
||||||
|
@ -286,6 +309,7 @@ export class CoreNavigatorService {
|
||||||
* Angular router automatically converts numbers to string, this function automatically converts it back to number.
|
* Angular router automatically converts numbers to string, this function automatically converts it back to number.
|
||||||
*
|
*
|
||||||
* @param name Name of the parameter.
|
* @param name Name of the parameter.
|
||||||
|
* @param params Optional params to get the value from. If missing, it will autodetect.
|
||||||
* @return Value of the parameter, undefined if not found.
|
* @return Value of the parameter, undefined if not found.
|
||||||
*/
|
*/
|
||||||
getRouteNumberParam(name: string, params?: Params): number | undefined {
|
getRouteNumberParam(name: string, params?: Params): number | undefined {
|
||||||
|
@ -299,6 +323,7 @@ export class CoreNavigatorService {
|
||||||
* Angular router automatically converts booleans to string, this function automatically converts it back to boolean.
|
* Angular router automatically converts booleans to string, this function automatically converts it back to boolean.
|
||||||
*
|
*
|
||||||
* @param name Name of the parameter.
|
* @param name Name of the parameter.
|
||||||
|
* @param params Optional params to get the value from. If missing, it will autodetect.
|
||||||
* @return Value of the parameter, undefined if not found.
|
* @return Value of the parameter, undefined if not found.
|
||||||
*/
|
*/
|
||||||
getRouteBooleanParam(name: string, params?: Params): boolean | undefined {
|
getRouteBooleanParam(name: string, params?: Params): boolean | undefined {
|
||||||
|
|
Loading…
Reference in New Issue