Skip to content

Commit

Permalink
feat: removing route guards in favor of NgxFeatureToggleRouteGuard
Browse files Browse the repository at this point in the history
  • Loading branch information
willmendesneto committed May 8, 2021
1 parent a89ce45 commit a64a6bc
Show file tree
Hide file tree
Showing 13 changed files with 244 additions and 604 deletions.
52 changes: 48 additions & 4 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,52 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased][]

### Added

- Adding `NgxFeatureToggleRouteGuard` route guard. This class can be used on the routes for the checks:
- `canLoad`
- `canActivateChild`
- `canActivate`

### Updated

- Removing other Route Guards in favor of `NgxFeatureToggleRouteGuard`. The replace should be a matter of find and replace the classes in your codebase.

E.G.:

```ts
...
export const routes: Routes = [
{
path: 'customer',
component: CustomerComponent,
// Before it was `NgxFeatureToggleCanALoadGuard`
canLoad: [NgxFeatureToggleRouteGuard],
// Before it was `NgxFeatureToggleCanActivateGuard`
canActivate: [NgxFeatureToggleRouteGuard],
// Before it was `NgxFeatureToggleCanActivateChildGuard`
canActivateChild: [NgxFeatureToggleRouteGuard],
data: {
featureToggle: ['enableCustomerPage'],
redirectTo: '/error',
},
children: [
{
path: ':id',
component: CustomerDetailComponent,
data: {
featureToggle: ['enableCustomerPage', '!enableChildrenNavigation'],
redirectTo: '/error',
},
},
],
},
...
];
...

```

## [10.1.0][] - 2021-05-07

### Added
Expand Down Expand Up @@ -485,7 +531,5 @@ So that, the new flow will be:
[9.0.0]: https://github.com/willmendesneto/ngx-feature-toggle/tree/v9.0.0
[unreleased]: https://github.com/willmendesneto/ngx-feature-toggle/compare/v10.0.0...HEAD
[10.0.0]: https://github.com/willmendesneto/ngx-feature-toggle/tree/v10.0.0


[Unreleased]: https://github.com/willmendesneto/ngx-feature-toggle/compare/v10.1.0...HEAD
[10.1.0]: https://github.com/willmendesneto/ngx-feature-toggle/tree/v10.1.0
[unreleased]: https://github.com/willmendesneto/ngx-feature-toggle/compare/v10.1.0...HEAD
[10.1.0]: https://github.com/willmendesneto/ngx-feature-toggle/tree/v10.1.0
21 changes: 11 additions & 10 deletions README.md
Expand Up @@ -170,7 +170,7 @@ export const routes: Routes = [
...
```

Also, you can use `NgxFeatureToggleCanActivateGuard` to check if the route should be activated or not by passing the class and configuration of the feature toggle to be checked in your route data.
Also, you can use `NgxFeatureToggleRouteGuard` to check if the route should be activated or not by passing the class and configuration of the feature toggle to be checked in your route data.

```js
...
Expand All @@ -179,7 +179,7 @@ export const routes: Routes = [
{
path: 'home',
component: HomeComponent,
canActivate: [NgxFeatureToggleCanActivateGuard],
canActivate: [NgxFeatureToggleRouteGuard],
data: {
// Using array as configuration
featureToggle: [
Expand All @@ -194,7 +194,7 @@ export const routes: Routes = [
{
path: 'dashboard',
component: DashboardComponent,
canActivate: [NgxFeatureToggleCanActivateGuard],
canActivate: [NgxFeatureToggleRouteGuard],
data: {
// Using string as configuration
featureToggle: 'enableSecondText',
Expand All @@ -212,7 +212,7 @@ export const routes: Routes = [
{
path: 'home',
component: HomeComponent,
canActivate: [NgxFeatureToggleCanActivateGuard],
canActivate: [NgxFeatureToggleRouteGuard],
data: {
// Using array as configuration
featureToggle: [
Expand All @@ -227,7 +227,7 @@ export const routes: Routes = [
{
path: 'dashboard',
component: DashboardComponent,
canActivate: [NgxFeatureToggleCanActivateGuard],
canActivate: [NgxFeatureToggleRouteGuard],
data: {
// Using string as configuration
featureToggle: 'enableSecondText',
Expand All @@ -239,15 +239,15 @@ export const routes: Routes = [

In this case, we are combining the checks. So the component will be activated if `enableSecondText` is configured as `true` AND `enableFirstText` is configured as `false`. With that configuration you can have all the flexibility to cover different scenarios in your app.

Use `NgxFeatureToggleCanActivateChildGuard` to control when the child component of a specific component can be activate via routing. It can be passed as an array of items.
Use `NgxFeatureToggleRouteGuard` to control when the child component of a specific component can be activate via routing. It can be passed as an array of items.

```js
...
export const routes: Routes = [
{
path: 'customer',
component: CustomerComponent,
canActivateChild: [NgxFeatureToggleCanActivateChildGuard],
canActivateChild: [NgxFeatureToggleRouteGuard],
children: [
{
path: ':id',
Expand All @@ -269,7 +269,7 @@ export const routes: Routes = [
{
path: 'dashboard',
component: DashboardComponent,
canActivateChild: [NgxFeatureToggleCanActivateChildGuard],
canActivateChild: [NgxFeatureToggleRouteGuard],
children: [
{
path: ':id',
Expand Down Expand Up @@ -300,8 +300,9 @@ export const routes: Routes = [
{
path: 'customer',
component: CustomerComponent,
canActivate: [NgxFeatureToggleCanActivateGuard],
canActivateChild: [NgxFeatureToggleCanActivateChildGuard],
canLoad: [NgxFeatureToggleRouteGuard],
canActivate: [NgxFeatureToggleRouteGuard],
canActivateChild: [NgxFeatureToggleRouteGuard],
// This is the featureToggle configuration for
// the parent component
data: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -86,7 +86,7 @@
"bundlesize": [
{
"path": "./dist/ngx-feature-toggle/bundles/ngx-feature-toggle.umd.min.js",
"maxSize": "1.9KB"
"maxSize": "1.82KB"
}
],
"engines": {
Expand Down

This file was deleted.

0 comments on commit a64a6bc

Please sign in to comment.