angular-i18next icon indicating copy to clipboard operation
angular-i18next copied to clipboard

Add i18next guard

Open kfrancois opened this issue 3 years ago • 1 comments

Summary

The experience of using

data: { i18nextNamespaces: ['...'] },
resolve: { i18next: I18NEXT_NAMESPACE_RESOLVER },

Is slightly brittle, as it's easy to forget I18NEXT_NAMESPACE_RESOLVER. Although easy to catch manually in development, it's hard to protect against regression during refactoring.

In our repo we added a helper to move this to a (functional) guard. This guard basically reimplements the i18nextNamespaceResolverFactory while adding the functionality of blocking navigation while namespaces are loading.

Example

Before

{
  path: 'rich_form',
  loadChildren: () => RichFormFeatureModule,
  data: { i18nextNamespaces: ['feature.rich_form'] },
  resolve: { i18next: I18NEXT_NAMESPACE_RESOLVER },
},

After

{
  path: 'rich_form',
  loadChildren: () => RichFormFeatureModule,
  canActivate: [i18NextNamespacesGuard('feature.rich_form')],
},

kfrancois avatar Mar 15 '23 11:03 kfrancois

@kfrancois Hi! Thank you for PR. Interesting idea. I should deep dive to it. Could you update your fork from master? I can't say right now... we might need both guard and resolver. But if we keep resolver - we need to make it also functional since Angular deprecated currently implemented resolver behavior

Romanchuk avatar Jun 09 '23 10:06 Romanchuk