1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-11 22:03:36 +00:00

[AC-2806] Add support for conditional routing based on feature flag value (#9798)

Co-authored-by: Shane Melton <smelton@bitwarden.com>
This commit is contained in:
Thomas Rittson
2024-06-27 06:43:02 +10:00
committed by GitHub
parent 76a3cb5a46
commit 794da48437
2 changed files with 56 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
import { Type } from "@angular/core";
import { Route, Routes } from "@angular/router";
import { CanMatchFn, Route, Routes } from "@angular/router";
/**
* Helper function to swap between two components based on an async condition. The async condition is evaluated
@@ -32,7 +32,7 @@ import { Route, Routes } from "@angular/router";
export function componentRouteSwap(
defaultComponent: Type<any>,
altComponent: Type<any>,
shouldSwapFn: () => Promise<boolean>,
shouldSwapFn: CanMatchFn,
options: Route,
altOptions?: Route,
): Routes {
@@ -46,12 +46,7 @@ export function componentRouteSwap(
const altRoute: Route = {
...selectedAltOptions,
component: altComponent,
canMatch: [
async () => {
return await shouldSwapFn();
},
...(selectedAltOptions.canMatch ?? []),
],
canMatch: [shouldSwapFn, ...(selectedAltOptions.canMatch ?? [])],
};
// Return the alternate route first, so it is evaluated first.