Passing list item index via router

When list item information should be on different page

There can be situation when list item is on page and its details on another. So question is how to deal with stateIndex. For this case you can pass list item index along with url params

<a href="#" [routerLink]="['/dictionaries', i]" class="card-link">Go To Values</a>

and on target component catch it and assign to stateIndex

constructor(private route: ActivatedRoute, private router: Router) {
    super();
    this.route.params.subscribe((params: Params) => {
      this.stateIndex = params.id;
    });
  }

and it will be passed to actions automatically.

Or with signal actions:

constructor(private route: ActivatedRoute, private router: Router) {
}
  

ngOnInit(): void {
    this.route.params.subscribe((params: Params) => {
      this.actions = signalActions(TodoStateActions, { 
        statePath: this.statePath, 
        stateIndex: params.id 
      });
    });
}

Last updated