From 2dc87d42b4d147dfee584edf1104b89088d0eb05 Mon Sep 17 00:00:00 2001 From: Pavlo Tkach <3469726+ptkach@users.noreply.github.com> Date: Mon, 2 Oct 2023 17:38:03 -0400 Subject: [PATCH] Fix console nextUrl stacking routes (#2164) --- .../src/app/registrar/registrar.guard.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/console-webapp/src/app/registrar/registrar.guard.ts b/console-webapp/src/app/registrar/registrar.guard.ts index b0d87195a..b12c4c0f8 100644 --- a/console-webapp/src/app/registrar/registrar.guard.ts +++ b/console-webapp/src/app/registrar/registrar.guard.ts @@ -13,7 +13,11 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { Router } from '@angular/router'; +import { + ActivatedRouteSnapshot, + Router, + RouterStateSnapshot, +} from '@angular/router'; import { RegistrarService } from './registrar.service'; @@ -26,13 +30,16 @@ export class RegistrarGuard { private registrarService: RegistrarService ) {} - canActivate(): Promise | boolean { + canActivate( + _: ActivatedRouteSnapshot, + state: RouterStateSnapshot + ): Promise | boolean { if (this.registrarService.activeRegistrarId) { return true; } - // Get the full URL including any nested children (skip the initial '#/') - // NB: an empty nextUrl takes the user to the home page - const nextUrl = location.hash.split('#/')[1] || ''; - return this.router.navigate([`/empty-registrar`, { nextUrl }]); + return this.router.navigate([ + `/empty-registrar`, + { nextUrl: state.url || '' }, + ]); } }