mirror of
https://github.com/google/nomulus
synced 2026-01-10 16:00:52 +00:00
Pass around the full URL in RegistrarGuard (#2139)
Previously this didn't properly deal with nested routings, e.g. "settings/whois". It tried to just pass "whois" as the next url which doesn't work with the router because it's nested under the settings. Using all parts of the URL allows us to handle the nesting.
This commit is contained in:
@@ -39,7 +39,7 @@ describe('RegistrarGuard', () => {
|
||||
|
||||
it('should not be able to activate when activeRegistrarId is empty', () => {
|
||||
guard = TestBed.inject(RegistrarGuard);
|
||||
const res = guard.canActivate(dummyRoute);
|
||||
const res = guard.canActivate();
|
||||
expect(res).toBeFalsy();
|
||||
});
|
||||
|
||||
@@ -48,14 +48,14 @@ describe('RegistrarGuard', () => {
|
||||
useValue: { activeRegistrarId: 'value' },
|
||||
});
|
||||
guard = TestBed.inject(RegistrarGuard);
|
||||
const res = guard.canActivate(dummyRoute);
|
||||
const res = guard.canActivate();
|
||||
expect(res).toBeTrue();
|
||||
});
|
||||
|
||||
it('should navigate to registrars when activeRegistrarId is empty', () => {
|
||||
const dummyRoute = { url: '/value' } as RouterStateSnapshot;
|
||||
guard = TestBed.inject(RegistrarGuard);
|
||||
guard.canActivate(dummyRoute);
|
||||
guard.canActivate();
|
||||
expect(routeSpy.navigate).toHaveBeenCalledOnceWith([
|
||||
'/registrars',
|
||||
{ nextUrl: '/value' },
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
// limitations under the License.
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Router, RouterStateSnapshot } from '@angular/router';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
import { RegistrarService } from './registrar.service';
|
||||
|
||||
@Injectable({
|
||||
@@ -25,10 +26,12 @@ export class RegistrarGuard {
|
||||
private registrarService: RegistrarService
|
||||
) {}
|
||||
|
||||
canActivate(state: RouterStateSnapshot): Promise<boolean> | boolean {
|
||||
canActivate(): Promise<boolean> | boolean {
|
||||
if (this.registrarService.activeRegistrarId) {
|
||||
return true;
|
||||
}
|
||||
return this.router.navigate([`/empty-registrar`, { nextUrl: state.url }]);
|
||||
// Get the full URL including any nested children (skip the initial '#/')
|
||||
const nextUrl = location.hash.split('#/')[1];
|
||||
return this.router.navigate([`/empty-registrar`, { nextUrl }]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user