I want to save the state of NavigationExtras Information of the navigation call into store. I try to use NgRx router-store for that.
I created a RouterStateSerializer, but i can't get access to the NavigationExtras data from here. The actual solution stores the state in the following navigation (because i use history.state).
Does anybody has an idea how to solve this?
export interface IRouterStateUrl {
url: string;
params: any;
state: any;
}
export class AppRouterStateSerializer implements RouterStateSerializer<IRouterStateUrl> {
serialize(routerState: RouterStateSnapshot): IRouterStateUrl {
const {url} = routerState;
const params = routerState.root.firstChild ? routerState.root.firstChild.params : {};
const state = history.state;
return {
url,
params,
state
};
}
}
Expect to find the navigation_extra data in the store.
was looking for an answer to this problem myself.
I found out a solution: first, you need to add the
@Injectable()
decorator to yourAppRouterStateSerializer
class, then you can inject theRouter
into your serializer. In the end, you can add theextra
property to yourIRouterStateUrl
and return{ url, params, queryParams, extras: this.router.getCurrentNavigation()?.extras || {} }
from your serializer.Resulting class