Lifecycle Hooks routerlink vs Browser URL?

Hi, I don't completely understand the Lifecycle Hooks via routerlink vs Browser URL?

For example, visiting localhost:4200/places/3983j3hhb21kj4 from clicking an item on a list on localhost:4200/places/ via routerLink

Versus

Typing directly localhost:4200/places/3983j3hhb21kj4 into my browser.

I'm seeing different behaviors when using a geocoder api. Works fine for the 2nd in the browser, just not on routerLinks.

Angular 7.2

Posted Apr 17, 2019, 1:04 AM UTC

02
Devstackr•

It could be because the component at the URL /places and /places/:id are the same. If this is the case, it should be noted that ngOnInit doesn't run each time you change the URL. You have to subscribe to the route changes in ngOnInit to get the desired behaviour.

2
ggeoff•

Can you share any code that shows your issue. I have seen this before in an app I worked on about a year ago. I couldn't tell you what our issue was though. I think it had something to do with some nested object and references being passed around an not be initialized correctly but may be wrong.

Edit: u/devstackr is right that is the exact problem I had a while ago.

Had a component stage that was the routed component. Also the navbar above it you could change the route but the component didn't have any input properties that changed when the route changed therefore it didn't rerender

1