In my application I retrieve all data in the "Items-Overview-Component" in the constructor. (router path: "/items"
).
// Items-Overview-Component
constructor(private store: Store<fromReducer.State>) {
this.store.dispatch(loadItems());
}
When clicking on an item entry, I navigate to "/items/:id"
. Then I retrieve the details from the store using the :id
.
// Item-Details-Component
constructor(private store: Store<fromReducer.State>) {
this.item$ = this.store.pipe(select(getItemDetails));
}
So far a very clear vanilla use case for an Angular project.
However, if the user navigates "hard" to a URL with a specific item (e.g. "/items/741"
), then the store is empty and no details can be retrieved.
How can I reload the data in NGRX "on demand"? Is there perhaps a one-time lifecycle hook that I should react to here?
BTW: I also use @ngrx/router-store