Skip to content

404 handling doesn't work #33

Description

@dan-overton
  • @kentcdodds/react-workshop-app version: 2.19.2
  • node version: 14.12.0
  • npm version: 6.14.8

What you did:

Navigated to a spurious route, e.g. /abcdef or an exercise that didn't exist, e.g. /99

What happened:

Screenshot 2020-10-19 at 22 02 55

When instead the NotFound component should have been rendered.

Reproduction repository:

You can reproduce this on any downloaded course section

Problem description:

The NotFound component is not rendered when an invalid URL is navigated to.

This is happening because:

  1. The /:exerciseNumber route is not scoped to just capture numbers, but any url. Therefore no url ever reaches the NotFound catch all route.
  2. The ExerciseContainer component does not check the bounds of exerciseInfo, so if the exerciseNumber passed in is invalid (either a string or a number outside of the defined exercises) the app crashes with a destructuring error as shown above.

Suggested solution:

  1. Scope the /:exerciseNumber/ route to only accept numbers, via regex. This should fix 404 handling for non number parameters.
  2. Add a bounds check and render NotFound in ExerciseContainer if the number passed is not found in exerciseInfo.

I'd be happy to submit a PR for the changes if desired.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions