I've implemented the following console outputs to follow what's executed and what's not. The code for a page under /dataList.
export class DataList implements OnInit {
constructor(private service: DataService) {
console.log("constructed");
}
ngOnInit() {
console.log("inited");
...
}
}
Now, it works as supposed providing both the outputs (i.e. constructed and inited) in the console when accessing the page by entering a URL and also when accessing the page using routing from another page, as show below.
this.router.navigateByUrl("/dataList");
However, it doesn't show initied (only constructed) when I navigate from this page to a detailed page (with URL like /dataElement/12345, with 12345 being an ID) and then return back to the the page /dataList executing the navigation by URL shown above. (If I then hit F5, I get to see both constructed and inited, though.)
I didn't think it was even possible to get into the constructor without getting into ngOnInit
, given the implemented interface but apparently, I was mistaken (and majorly baffled too).
The best diagnostics that I can up with is that when navigating from a route of subpath, the initialization isn't invoked. But it seems so weird to me so I'm suspect I haven't diagnosed it correctly, neither. Googling produced nothing that I recognized as adequately related (like this or this). And the routing is like this.
const routes: Routes = [
{ path: "", component: StartComponent },
{ path: "dataList", component: DataListComponent },
{ path: "dataElement/:id", component: DataElementComponent },
...
{ path: "**", component: StartComponent }
];