Custom serialization

The object being stored is a bit verbose though. It contains a lot of information and we may only be interested in parts of it. We can actually solve that by building our own custom serializer. We need to do the following to accomplish that:

  • Create a class that implements the interface RouterStateSerializer and decide what we want to return
  • Replace the router key RouterStateSerializer with our custom implementation

Let's begin. We first create a class, like so:

// my-serializer.tsimport { RouterStateSerializer } from '@ngrx/router-store';import { RouterStateSnapshot } from '@angular/router';interface MyState {  url: string;}export class MySerializer implements RouterStateSerializer<MyState> {  serialize(routerState:

Get Architecting Angular Applications with Redux, RxJS, and NgRx now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.