Update PageNotFoundView.vue #814
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🔧 Fix: Improved Navigation Handling on the "Page Not Found" Page
🐞 Problem Overview
When a user lands directly on the "Page Not Found" screen (for example, by typing an invalid URL or clicking a broken link), the app tries to send them back to their last visited page. However, in these situations, the app doesn’t actually know where they came from because they arrived from outside the site. This causes the system to fail when trying to go "back"—sometimes even resulting in the app crashing or showing nothing when the user clicks the "Go Back" button.
This is frustrating for users, especially since the 404 page is supposed to help guide them back—not trap them.
🔍 Root Cause
The 404 page depends on a value called prevRoute, which stores where the user came from. This value is captured when users navigate inside the site. But if someone enters the 404 page directly (from outside the app), that value is missing or incomplete. The code was trying to use this missing information without checking if it existed, which led to errors.
✅ What Was Done
To solve this, we added a simple but important improvement:
The app now checks if the previous route information is actually available.
If it is, the "Go Back" button works as expected.
If it isn’t (such as when a user lands directly on the 404 page), the app now redirects them to the homepage instead—gracefully and without errors.
This change makes the "Go Back" button work in all scenarios and ensures the app won’t crash or behave unexpectedly.
🧪 What We Tested
We verified that:
Users who visit a broken link from inside the app are correctly sent back to where they came from.
Users who land on the 404 page directly (like from an external link) are taken to the homepage.
No crashes or errors occur in any case.
Everything works properly on modern browsers like Chrome and Firefox on Windows.
📦 Where This Applies
This update affects the component that handles the 404 or "Page Not Found" screen.
🏁 Outcome
The app now handles navigation on the 404 page in a smarter and more user-friendly way. It prevents crashes and ensures that all users—whether coming from inside or outside the app—are smoothly guided back to a working part of the site.