The app
directory contains the following directories:
actions
components
directives
effects
guards
interceptors
models
pipes
reducers
selectors
views
@ngrx/router-store
is not used for maximum flexibility. Instead the following routing-related entities occupy the app:
RouteModel
NavigateAction
StoreRouteAction
routeReducer
RouteEffects
whenNavigated()
NavigateDirective
- A link with the
[appNavigate]="{view: RoutePath.Recipes, id: recipe.id}"
directive is clicked. The directive dispatches aNavigateAction
with the inputtedRouteModel
as its payload. - Each instance of the
whenNavigated()
operator (hooked onto theactions$: Actions
observable) catches theNavigateAction
and passes theRouteModel
in 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 theGetRecipeRequestAction
and triggers the resource's retrieval.
- Based on the specified predicate, the mapper function defined in the
- The
RouteEffects.navigate$
effect also catches theNavigateAction
, serializes theRouteModel
in 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
NavigationEnd
event, 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
routeReducer
catches theStoreRouteAction
and stores theRouteModel
in its payload in theroute
slice of the app state.