Angular functional route guard with ngrx store

251 Views Asked by At

I've searched everywhere and I've only been able to find the deprecated class-based Canactivate implementation of a route guard that accesses an ngrx store.

Can someone provide an example of a functional route guard that accesses an ngrx store?

1

There are 1 best solutions below

0
timdeschryver On

The implementation would be the same. The only difference is that you don't inject the store with the constructor, but that you're using the new inject method provided by Angular.


export function myRouterGuard(): Observable<boolean|UrlTree> {
  const store = inject(Store);

  // implementation comes here
}