课程: React: Creating and Hosting a Full-Stack Site

免费学习该课程!

今天就开通帐号,24,700 门业界名师课程任您挑!

Loading data For React Router routes

Loading data For React Router routes

- [Instructor] All right, so now that we've installed Axios, let's see how we can actually load data for the different routes in our React application. So, what I'm going to do is I'm going to open up the frontend application again. We haven't been in here in a little while, but we're going to go into App.jsx and take a look at the routes array that we created inside of there. Now, remember that what this Routes Array did is it defined what component, right, what page component should be displayed for each path. So, we had this surrounding Layout component that basically was in charge of displaying the nav bar, and then we had the HomePage, AboutPage, ArticlesListPage, and ArticlePage. So, what we're going to need to do here in order to load data for one of these pages is we actually just need to specify another property in one of these objects, and that is a property called loader. Now, the way that this works is we simply need to specify a function for this loader property that will…

内容