- Overview
- Transcript
4.8 Challenge: Route Not Found
1.Introduction2 lessons, 04:39
1.1Introduction01:31
1.2Application Demo03:08
2.Get Started With Redux6 lessons, 41:43
2.1Set Up the Project09:34
2.2Reducers and Actions10:10
2.3Combining Reducers08:42
2.4Challenge: Add a Case to a Reducer04:44
2.5Challenge: Split a Reducer05:19
2.6Challenge: Build a Component03:14
3.Create React Components8 lessons, 50:18
3.1Build a Pure Component04:53
3.2Start the Sidebar04:31
3.3Write Action Creators08:37
3.4Use Action Creators06:42
3.5Challenge: Temperature Converter05:50
3.6Challenge: Todo List09:21
3.7Challenge: Action Creators07:26
3.8Challenge: Refs Research02:58
4.Application Structure9 lessons, 56:09
4.1Refactor Our Application for Growth08:43
4.2Using the `react-redux` Package13:12
4.3Add a Router07:24
4.4Create Nested Routes07:44
4.5Add `localStorage` Support03:38
4.6Challenge: Presentational and Container Components07:26
4.7Challenge: Basic Routing02:53
4.8Challenge: Route Not Found02:51
4.9Challenge: Route Parameters02:18
5.Implement the App9 lessons, 1:31:34
5.1Create the Toolbar06:16
5.2Create the New Card Modal15:16
5.3Display a Deck of Cards05:27
5.4Create the Edit Card Modal10:20
5.5Filter Cards06:24
5.6Create a Study Interface19:29
5.7Add Asynchronous Actions13:08
5.8Challenge: General Conversion Component07:11
5.9Challenge: Users List Component08:03
6.Conclusion1 lesson, 01:32
6.1Conclusion01:32
4.8 Challenge: Route Not Found
In this challenge, we begin with a simple application that has a home route. And our challenge is to add a route to redirect unhandled routes to a Route Not Found component. I want to say before we get started here that we are using the version of React Router that we used throughout this course. And so, that means it's a little bit of an older version of React Router, which has changed its API recently, with the release of React Router 4. However, the general concepts will be very similar here. So maybe as some bonus work after this lesson, you can go take a look at how you might do this with React Router 4. But honestly, it's not too different. So if you're gonna do this challenge yourself, go ahead and fork this codePen. And you can pause this video now because I'm going to show you what my solution will be. So right now with our homepage if I click page A or page B, you can see that nothing happens because we don't actually have a route for them. So when our link come on here tries to move to /A or /B, there is nothing to go and so it just does it. So what we need to do is add a general route that will match anything that is not already matched. Now for the most part, when you have sibling routes here in a React Router, they will match from top to bottom. So, we need to put our catch all route at the very bottom. So this is going to be a route and the path is just going to be an asterisk. So it matches everything. And then the component, we'll call it RouteNotFound. Now all we have to do is make this component. So just above this let's create a function called RouteNotFound and this is going to take some props. And this is gonna take some props and we can actually say what route that was I found was. So we can say the route and then I will put it in there in a second and what to say was not found. So what are we gonna put in here? Well, it's going to be prompts.location.pathname. The [INAUDIBLE] router gives us a location property and from that, we can get the path name, which is the URL that the user tried to navigate to. So now if I click page A, you can see the route /a was not found. We can go back and go to page B and the route /b was not found. Of course, if one of these was to match, so for example, if we had route path of /a in here and and we'll just make a really quick page A component. So now if I click page A, we'll go to page A, but if I click page B, the route /b was not found. So having a not found route is really simple in React Router. In fact, I believe in the most recent version of React Router, you don't even need to specify a path. And I'm kind of giving away the instructions here, but this is a little bit more that's different in React Router 4. So, you can explore that if you'd like. But that's it for this challenge. Nice work.