Angular 16 Resolvers - How to handle redirection to child

495 views Asked by At

I'm just really looking for some general advice on best practice here as it's the first time I've had to use resolvers.

So the current flow of my application...

  • App initialisation function to check auth and either authenticate user or not if they still have auth token

  • resolver on the root '' path that basically does a whole bunch of set up for the route the user goes to after logging in. This resolver finally redirects to a child route.

  • resolver on child route to do some final configuration setup

Now I just want to check if this structure is right or wrong?

Sone of the problems I can think of is...

  1. It could result in an infinite loop as I'm navigating to a child from the parent resolver

  2. From what I understand its bad practice to do route navigation in a resolver and resolver should be purely for data setup

  3. The routing from the parent resolver oddly doesn't seem to change the url. I'm assuming this is a side effect of redirecting in a resolver?

So what would be the correct flow for me to use here?

1

There are 1 answers

3
Matthieu Riegler On

Yes you're right the resolver shouldn't fire navigation.

Navigation should be fired by guards like canActivate !