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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user