Note: I found some code snippets online but, after testing them out, I have doubts about their reliability due to inconsistencies.
In my script, I have developed two utility functions - one for moving to the parent node and another for reloading the current page. The first function works correctly while the second one fails to trigger the reload operation.
goToParent(route: ActivatedRoute) {
const options: NavigationExtras = { relativeTo: route };
this.router.navigate([".."], options);
}
reloadCurrentPage(route: ActivatedRoute) {
this.router.routeReuseStrategy.shouldReuseRoute = () => false;
this.router.onSameUrlNavigation = "reload";
const self = ".";
this.router.navigate([self]);
// const options: NavigationExtras = { relativeTo: route };
// this.router.navigate(["."], options);
}
I followed the solution here, with the only difference being that I want the target path to be dynamic rather than hardcoded. I've experimented with various parameters like self="." and self="" but haven't been able to achieve the desired reload effect.
What am I overlooking?
I also attempted to extract information from the route object passed into the service's method, but all I see are observables instead of actual segments. Additionally, using this.router.navigate(route) resulted in an error.
After searching online, I came across numerous suggestions with conflicting advice (e.g., this), which makes me suspect that the solution could be version-dependent (I'm using 8.0). Moreover, many of the recommendations, while popular, may lead to unintended consequences in the long run without my awareness.