Nas3nmann / ngx-deep-linking

A library for automatically deep linking
MIT License
7 stars 1 forks source link

Angular livecycle hoks are not called when navigating to the same wrapped component with different parameters #12

Closed wertzui closed 2 years ago

wertzui commented 2 years ago

I need to call a method after all the @Input()s have been set.

I tried using ngOnInit() to do that. However it is only called, after the app has navigated to the wrapped component for the first time.

In my AppModule, I have imported the RouterModule like this:

@NgModule({
  declarations: [
    AppComponent,
    ...
  ],
  imports: [
    RouterModule.forRoot(AppRoutes, { onSameUrlNavigation: 'reload' }),
    ...
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

My AppRoutes look like this:

export const AppRoutes: DeepLinkingRoute[] = [
  { path: '', component: HomeComponent, pathMatch: 'full' },
  {
    path: 'list/:apiName/:rel',
    runGuardsAndResolvers: 'always',
    component: DeepLinkingWrapperComponent,
    wrappedComponent: RESTworldListViewComponent,
    deepLinking: {
      params: [
        { name: 'apiName', type: 'string' },
        { name: 'rel', type: 'string' }
      ],
      queryParams: [
        { name: 'editLink', type: 'string' },
        { name: 'initialOrdering', type: 'json' }
      ]
    }
  },
  ...
];

Now I navigate to /list/foo/bar. Everything works fine and ngOnInit() is called.

Now I navigate to /list/foo2/bar2 ngOnInit() is not called.

Is it possible to have the Angular LifeCycle hooks being called after the second navigation happened? If not, is there any other possibility to get notified, after all the @Input()s have been set? Please note that I cannot just check if all have a value, since it is expected that some may be undefined.

Thanks in advance

Nas3nmann commented 2 years ago

I think this is rather desired behavior, because the actual RESTworldListViewComponent is only initialized once and afterwards only the two pathParam inputs change. So I think what you're looking for is rather the ngOnChanges lifecycle hook, that fires whenever one of your component inputs changes.