The app directory contains the following directories:
actionscomponentsdirectiveseffectsguardsinterceptorsmodelspipesreducersselectorsviews
@ngrx/router-store is not used for maximum flexibility. Instead the following routing-related entities occupy the app:
RouteModelNavigateActionStoreRouteActionrouteReducerRouteEffectswhenNavigated()NavigateDirective
- A link with the
[appNavigate]="{view: RoutePath.Recipes, id: recipe.id}"directive is clicked. The directive dispatches aNavigateActionwith the inputtedRouteModelas its payload. - Each instance of the
whenNavigated()operator (hooked onto theactions$: Actionsobservable) catches theNavigateActionand passes theRouteModelin its payload to the passed-in mapper function.- Based on the specified predicate, the mapper function defined in the
RecipeDetailEffects.requireRecipeById$effect returns a newGetRecipeRequestAction, which is therefore dispatched. - The
RecipeDetailEffects.getRecipeById$catches theGetRecipeRequestActionand triggers the resource's retrieval.
- Based on the specified predicate, the mapper function defined in the
- The
RouteEffects.navigate$effect also catches theNavigateAction, serializes theRouteModelin the action's payload to a URL and passes it to theRouter.navigateByUrl()method. - The router's navigation cycle begins. The
RecipeDetailGuard.canActivate()method is invoked (due to routes config in theAppRoutingModule) and allows the routing to continue only when the necessary resource (recipe detail) has been loaded. - The router's navigation cycle ends with the
NavigationEndevent, which gets caught by theRouteEffects.storeRoute$effect. The URL carried by the event is parsed into aRouteModel, which becomes the payload of a newly dispatchedStoreRouteAction. - The
routeReducercatches theStoreRouteActionand stores theRouteModelin its payload in therouteslice of the app state.