Skip to main content

Installation

Fetching the package

Install @ngx-flagr/routing using the package manager of your choice:

npm install @ngx-flagr/routing
info

@ngx-flagr/routing relies on functionalities provided by @ngx-flagr/core, be sure to have it properly set up

Initialization

Once installed, provide it to your application. You can do so either by using the provider, favored for the standalone API, or the former way, in your app.module.ts:

In the main.ts file, you can call provideNgxFlagr in the providers array and pass in which service should be used for the feature flags evaluation:

main.ts
import { bootstrapApplication } from '@angular/platform-browser';

import { provideNgxFlagr } from '@ngx-flagr/core';
import { provideNgxFlagrRouting } from '@ngx-flagr/routing';

import { AppComponent } from './app/app.component';
import { CustomFeatureFlagService } from './app/custom-feature-flag.service';

bootstrapApplication(AppComponent, {
providers: [
provideNgxFlagr({ featureFlagService: CustomFeatureFlagService }),
provideNgxFlagrRouting(),
],
}).catch(err => console.error(err));

Customizing its behavior

@ngx-flagr/routing provides a default configuration for its behavior that you can override for your needs.

PropertyTypePurposeDefault Value
keys.featureFlagstringThe key used to identify feature flags in the data property of Angular routes'featureFlag'
keys.redirectToIfDisabledstringThe key used to identify the route to which the user will be redirected in the data property of Angular routes'redirectToIfDisabled'
redirectToIfDisabledstring | nullThe name of a route to redirect to if the user does not have the feature flag enablednull
validIfNonebooleanThe value returned by the guard when no feature flags are defined for a routefalse
note

Here is the full default configuration:

const DEFAULT_ROUTING_CONFIGURATION: NgxFlagrRoutingConfiguration = {
keys: {
featureFlag: 'featureFlag',
redirectToIfDisabled: 'redirectToIfDisabled',
},
redirectToIfDisabled: null,
validIfNone: false,
};