课程: React: Creating and Hosting a Full-Stack Site
免费学习该课程!
今天就开通帐号,24,700 门业界名师课程任您挑!
Using route parameters in loaders - React.js教程
课程: React: Creating and Hosting a Full-Stack Site
Using route parameters in loaders
- [Instructor] All right, so now that our front end is successfully loading article data from our server, the last thing that we really need to do in order to make sure that it's the right data is replace this hard-coded name for the article with whatever the route parameter happens to be that we're currently visiting, right? So essentially, we want to take this name parameter and insert it into this string. Well, as it happens, this is actually incredibly easy to do. We can just add a single prop here called params to our function, right, our loader function that we're defining, and React will automatically pass these params, right, such as name, to our function. So all we have to do now is take away this learn-node thing, and onto the end of this we're going to say + params.name, and that should be all we really need to do there. It's pretty straightforward, right? So let's just check and make sure that this works, and first of all, we know that our learn-react article already has…
内容
-
-
-
-
-
-
(已锁定)
The Axios library1 分钟 17 秒
-
(已锁定)
Loading data For React Router routes4 分钟 40 秒
-
(已锁定)
Using the useLoaderData hook6 分钟 12 秒
-
(已锁定)
Using route parameters in loaders3 分钟 58 秒
-
(已锁定)
Displaying comments3 分钟 21 秒
-
(已锁定)
Creating an upvote button4 分钟 29 秒
-
(已锁定)
Creating an add comment form8 分钟 26 秒
-
(已锁定)
-
-
-