angular - Trigger guard to re-render component when change url manually via browser -


i setup routing this

{      path: ':parent', component: parentcomponent,      resolve: { data: parentresolve },      children: [          {               path: ':child', component: childcomponent,               resolve: {                    data: childresolve               }          } } 

everything works when change url /:parent/:child /:parent. want redirect child route param parentresolve.

my problem: angular not call resolve guard when change url hand can't redirect child route.

please ask me if you're not clear, thank you.

the 'resolve' part in router config handling of route fetching before it's been activated. that's mean called when entering route form other route , not it's own children (because route activated).

i think best way approach issue add route change event listener parentcomponent , handle on there.

try this:

export class parentcomponent implements oninit, ondestroy {   routeeventsubscription$;   routerdata;   constructor(private activatedroute: activatedroute,               private router: router) {     this.name = `angular! v${version.full}`   }     ngoninit() {     this.subscribetoroutechange();   }    subscribetoroutechange(){     this.routerdata=this.activatedroute.snapshot.params['data'] //your router resolver data.     this.routeeventsubscription$ = this.router.events       .filter(event => event instanceof navigationstart) //subscribe navigationstart event       .subscribe(event => {         this.routetochild();       });   }    routetochild(){     /**      * add logic here.      * use this.routerdata you.      */   }      ngondestroy(){     //dont forget unsubscribe routeeventsubscription$!     this.routeeventsubscription$.unsubscribe();   }   } 

you can read more route data resolve here , here


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -