FAQ: React Router - Nested Routes

This community-built FAQ covers the “Nested Routes” exercise from the lesson “React Router”.

Paths and Courses
This exercise can be found in the following Codecademy content:

React Router
(Beta) Learn React Router

FAQs on the exercise Nested Routes

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in #get-help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to #get-help and #community:tips-and-resources. If you are wanting feedback or inspiration for a project, check out #project.

Looking for motivation to keep learning? Join our wider discussions in #community

Learn more about how to use this guide.

Found a bug? Report it online, or post in #community:Codecademy-Bug-Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

This section doesn’t seem to work, either…

The username doesn’t appear to be set properly as all I see after clicking Profile is this:

Screenshot from 2022-01-04 10-07-26

To investigate, I dumped the value of currentUser within Profile.js to see what the value was:
Screenshot from 2022-01-04 10-10-16

It seems the username isn’t there:
Screenshot from 2022-01-04 10-10-06

Hi there, I’ve done some digging around and was able to replicate your error if I didn’t update the Header.js file with NavLinks to replace the a tags — specifically, if link that redirects to /profile is an a tag, it will cause the page to reload, thus losing the username that you had entered.

If you include NavLinks instead of a tags, you will get the desired behavior ONLY if you click on the profile button. Even if you have the proper NavLinks, if you were to enter your username and then manually navigate to /profile in the URL bar, you would lose the username. Why? Because this application is quite simple in the way it “signs users in”. Unlike more realistic sign-in features, this application simply stores the username in the browser’s memory which gets wiped when you refresh the browser which, as we learned, happens when you click on an <a> tag or if you navigate to a URL in the browser. In a more realistic application, when a user signs in, that data would be stored in some back-end service or in the browser’s cache (or something like that).

I hope this helps!

3 Likes