department-of-veterans-affairs / va.gov-team

Public resources for building on and in support of VA.gov. Visit complete Knowledge Hub:
https://depo-platform-documentation.scrollhelp.site/index.html
282 stars 201 forks source link

Appointments React App Does Not Handle Unknown URLs #78040

Open JRRoof opened 6 months ago

JRRoof commented 6 months ago

Description

Currently, an HTTP 404 error code is generated by the VA web server if a veteran tries to access an unknown or bad URL on the VA site for a static content page (e.g. https://www.va.gov/dummy). The web server is set up to respond to HTTP 404 error codes by showing a "page not found" page to the user as shown below. This works well for static content served by the web server. However, dynamic content that gets rendered on the client side (like from a React app) cannot generate HTTP codes for missing pages for the web server to respond to. All React apps that the VA site uses render on the client side. Each React app has a specified root URL in its manifest.json file (e.g./health-care/schedule-view-va-appointments/) that links to the app regardless of any sub-path provided in the URL (e.g. /health-care/schedule-view-va-appointments//path/path/path leads to the same React app). The apps use React Router conditional code to render content based on the child path(s) of the root URL (e.g. /path/path/path). An empty or incomplete page can result if the app’s routing logic does not explicitly handle the provided path(s). A sample of this behavior can be found below.

image.png

This results in the VA site rendering empty or incomplete pages with no further information or action for the user.

Recommendation

React apps have various routing patterns that restrict our ability to implement a catch-all solution at the React Router level. These various patterns also mean that the routing for some apps may need to be refactored in order to properly handle unknown URLs. Our recommendation is as follows:

  1. Create a shared page-not-found component to be used by all React apps. This component should replicate the existing static content 404 page for a consistent user experience.
  2. Update each app to have a default React route that shows this new page-not-found component. This may need to be done for child paths as well. This implementation will retain the unknown URL in the browser’s address bar allowing the user to inspect/fix the URL. This will also duplicate the existing behavior of the static content 404 page. For example, we can add the following default route to an app to serve the page-not-found component for unknown URLs.
  1. Add documentation requiring a default route for all React apps and to use the shared page-not-found component. It should be noted that the page-not-found page should contain any other app content (some apps generate content like breadcrumbs before the routing logic). It also needs to be noted to generate the page-not-found page for any child routing that is not supported.
  2. Open tickets to get the different React apps updated to have default routes. This could be done by one team updating all the apps or individual tickets for each app. A lot of the apps can be quickly and easily updated since they have simple routing, so perhaps one person can update a lot of them at the same time.

Slack Canvas outlining issue and ask


Acceptance Criteria

Given an authenticated user When navigating to an unknown or bad URL starting with va.gov/my-health/appointments/ Then page-not-found component is displayed

Design Assets

All spec copy is FPO. Use copy in copy doc.

Definition of Done


How to configure this issue

JRRoof commented 1 month ago

The component can be found here: https://github.com/department-of-veterans-affairs/vets-website/blob/main/src/platform/site-wide/user-nav/components/PageNotFound.jsx

You can import it using: import PageNotFound from '@department-of-veterans-affairs/platform-site-wide/PageNotFound';