2
votes

I have several routes each with a table that should load data from the server. How can I dispatch an action to the ngrx/store to load data from the server when a route with table become active?

Thanks

1
What router version? What Angular2 version? Adding some code that demonstrates what you try to accomplish or what you have tried wouldn't hurt. - Günter Zöchbauer

1 Answers

2
votes

You can use the @ngrx/router-store that dispatches actions on different lifecycle steps.

Then add an effect that listen to ROUTER_NAVIGATED for example filters on a specific location and dispatches the needed loading action.

@Effect()
$routerNavigated = this.actions$.ofType(ROUTER_NAVIGATED)
.pipe(filter(action => (/persons/g).test(action.payload.url)),
map(action =>  new LoadSomePersonsData()));