Question Details

No question body available.

Tags

angular

Answers (1)

March 12, 2026 Score: 0 Rep: 23,420 Quality: Medium Completeness: 80%

I ended up using guards as suggested by @SherifElmetainy in the comments above:

import { createUrlTreeFromSnapshot } from "@angular/router";

export const ensureDefaultQueryParamsGuard: CanActivateFn = (newRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean | UrlTree => {

const router = inject(Router); const oldUrlTree = router.parseUrl(router.url);

// Copy the customer Id from the old route to the new one const myCustId = oldUrlTree.queryParams.feature; if (myCustId && !newRoute.queryParams.myCustId) { const newQueryParams = { ...newRoute.queryParams, myCustId }; return createUrlTreeFromSnapshot(newRoute, ["."], newQueryParams); }

// If the custId is already in the naviation route, continue with the // original navigation return true; }