Using route resolver I am trying to get a data from store as follows
export class GetActiveCustomerService implements Resolve<any> {
constructor(private store: Store<AppState>) {}
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): any {
return this.store.select('customer').pipe(
first(),
map((data) => {
return data.customer;
})
);
}
}
The previous attempt always returns null
What is the correct way to resolve the data stored in the store?
update 0
This modification returns the expected result. But when refreshing the browser the data is null. I understand it is because of take(1)
. If this is the route to achieve what I mentioned, how can I make the data survive refreshing?
export class GetActiveCustomerService implements Resolve<any> {
constructor(private store: Store<AppState>) {}
private getActiveCustomer(): Observable<any> {
return this.store.select('customers').pipe(take(1));
}
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): any {
return this.getActiveCustomer();
}
}
update 1
I found this answer
https://stackoverflow.com/a/58711499/615274 from someone who was facing a problem similar to mine. And the accepted solution uses take(1)
or first()
. But in my local when refreshing the obtained data it becomes null
. What is the proper way to handle this scenario?