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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.