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

免费学习该课程!

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

Using route parameters in loaders

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…

内容