In my current scenario, I am monitoring the parameters of the active route in order to update the content being displayed.
Within my component's ngOnInit()
function, I have implemented the following logic:
this.activeRoute.paramMap
.pipe(
switchMap((params) => {
this.fileName = String(params.get('filePath'));
return this.fileService.checkIfFileExists(this.fileName);
}),
tap((result) => {
if (!result) {
this.router.navigate(['/']);
}
}),
filter((result) => result),
switchMap(() =>
this.modificationService.getFileModifications(this.fileName)
),
tap((result) => {
if (result.allModifications) {
this.modificationList = result.allModifications;
this.noModification = false;
}
})
)
.subscribe();
Providing more context:
- If the file does not exist: the router redirects the user to /
- If the file exists, there are two scenarios:
- Modifications are found: they are displayed
- No modifications are found, a 404 error is triggered, which should display "no modifications found" on the website
The current behavior is as follows:
- If I navigate to a page for a file with modifications, they are displayed correctly
- Upon switching to another file that also has modifications, the display updates accordingly
- However, when switching to a file with no modifications and receiving a 404 error, the observable ceases to function. The content remains stuck on the last file with modifications displayed, even though the URL (and filePath parameter) changes
I navigate between files using a menu without refreshing the page. It works fine after a manual refresh.
Although I attempted to use catchError()
from RxJS, it did not alter the behavior other than suppressing the error message in the console.
Previously, I had only implemented:
this.router.routeReuseStrategy.shouldReuseRoute = () => false;
Instead of utilizing the deprecated code block this.activeRoute.paramMap...
, which I prefer not to use. The paramMap Observer functions smoothly in my other components that do not deal with 404 errors.
Any assistance would be greatly appreciated :)