Skip to content
Advertisement

What is wrong with the React components Route?

Attempting to build a flashcard app with React and React Hooks, I am able to get my home screen rendered. When introducing Router, I am able to click the link, update the path to be the one I am looking for, but nothing is being rendered from that new page.

App.js

JavaScript

ShowAllDecks.js –> List of flashcard decks

JavaScript

Deck.js –> Individual deck of flashcards

JavaScript

ViewDeck.js –> Should be a new screen for individual flashcard deck where I can view the list of cards in the deck, edit the cards, or add new cards.

JavaScript

When on the index route, flashcards is an array of objects and flashcard is a deck of cards object. What am I doing wrong with my Routes or components that make my component not render?

Example of the URL:

JavaScript

Advertisement

Answer

Since in your Sandbox you left the Deck element empty, I had to come up with my own:

JavaScript

But the idea is simple, you need to define your Routes at the higher level and then just create links to the routes inside your Deck element. Here is how your route definitions should look:

JavaScript

Here is a working Sandbox.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement