- Overview
- Transcript
4.9 Challenge: Route Parameters
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.9 Challenge: Route Parameters
Challenge 11 is our last challenge involving routers. In this lesson, we have two links, one going to /hello/Kari and one going to /hello/Adam, and what we wanna do is make both these links render the same component. So, we need some way to have a parameter in a route that can be different things. If you wanna figure this out on your own, go ahead and fork this CodePen. You can find the link to this underneath the video, of course, and if you'd like to do that, go ahead and pause now because I am going to show you my solution. As you can see, right now if we were to click carry Or Hello Adam. We have nothing here because we have a road not found component being rendered in our catch all route. So we need to put some route in the middle. So of course, this is going to be a route with a path, and the path is going to be / Hello and then slash colon name. And when we prefix part of our route here with a colon that means this is a variable that can be anything in this path. We can say that and then we need to Having a component here, and let's create a component that we're going to call hello. And let's create our hello component. So we'll put that right here, const Hello. And this is course is going to take some props. And we have a note up here which actually helps us out. You can use props.roteParams to get the parameters from a route and this has changed in the latest version of React. It's now Props.match.params but it's the same principle applies really. So here we can get our h1 and we'll say Hello and then in here we can say props.routeParams and then we can just use whatever name we called our token in the route. So in this case that's name. And that's our hello component. So now if I click, Say hello to Kari. We get, Hello Kari. If I click, Say hello to Adam, we get Hello Adam. And we can actually edit this in our little location bar here. So I can say, Andrew for example. Or we can say. Tuts+, notice that if we completely take off the name we get nothing here because that doesn't match one of our routes. Our route requires a name after that trailing slash. So as long as we give it anything there we will match that route. Okay, so there we go we have finished our route parameters challenge and you have successfully created a route that can match A pattern of route instead of a specific hard code of route. Good job!