- Overview
- Transcript
4.7 Challenge: Basic Routing
This app has a home route and component. Your challenge is to add two new routes and corresponding components:
- Route
/a
connecting to componentPageA
. - Route
/b
connecting to componentPageB
.
Add links between the pages so it is easy to navigate from one to the other.
Related Links
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.7 Challenge: Basic Routing
Our next challenge has to do with some basic routing. Although the version of React Router has kind of updated since this course was produced, these principles still apply. So as you can see our app has a home route and a component and we need to add some routes and components. We need to add a route/a which points to a page A and a route/b which points to a component page B. And then we have to have these components link to each other. So this is a great little exercise for getting familiar with using React Router, and more specifically, React Router's link component. So let's go ahead and fork this. And if you want to do this challenge yourself, go ahead and pause the video now. Okay, so let's see what we have here. At first we create an in memory router and this is nice for testing because we don't need to actually have access to an address bar. React router will just store the rote changes in memory. However, we do have a location bar component which kind of acts like the location bar for us. So this is actually pretty great. So as you can see, the homepage, our index route, or rendering gives us two links here. It gives us a link to /a and a link to /b for page A and page B. So what we wanna be able to do is click these links and go to those pages, so we're gonna need to start by creating the components for those. So we will start by creating a component called Page A. This is just going to be a basic div here, and at the top, let's have an h1 which says Page A. And then underneath this, let's have a paragraph, maybe, and in here, we can have a link to Page B, and we'll just say Page B, and we'll close off our link, excellent. So now, down here inside of our Router, let's go ahead and add a route for that. So we can create a route here and the component for this is going to be, page A, but we also need to give it a path and the path for this is /a. So now over here, I could go ahead and click Page A, and this will render our Page A component. If I click Page B, we don't actually have a /b route yet, so we need to create that next. So I'm gonna go ahead and just copy the page that we created for Page A, and we will change this to be called Page B. Change the h1, and then we'll change the link to Page A. And so now, we can create another route in our Router here. The path here will be /b, and the component is going to be Page B. There we go. So let's save that and now from our homepage here we can go to Page B. And this we'll take us to Page A and we can go back and forth between Page A and Page B. Looking at our location bar, we can go back to the home route as well and we go to Page A or to Page B individually. Excellent, so that's really all you needed to do. This is a pretty simple excercise but it gets you used to the idea of creating components that are top level components that are meant to be rendered as an entire page. So that is our basic routing challenge.