Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
With React Router, you are able to declare dynamic routes using special URL parameters. The data passed to the URL parameters can be displayed in your app.
Note
React Router has since added a change to react-router-dom version 6.4+ where you can no longer use multiple parameters in one dynamic route segment, /:fname-:lname
for example.
You can read about it here in the React Router documentation.
You will first have to change the second segment of the route's path in App.js to one parameter like path=":topic/:name"
. Then we'll need to change lines 5 and 6 of Featured.js to the following...
let { name, topic } = useParams();
name = name.replace('-', ' ');
Here we're destructuring our params similar to before, but then we're reassigning name
's value by removing the hyphen between the first and last names and replacing it with a space.
Resources
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up