skip to Main Content

I created an app using create-react-app and I have nested routes in my App.js. The Public component displays but nothing else does , such as /login or /home.

I added the /login just to test out a simple page, because Dash Layout is also nesting other elements but it does not render. I don’t think it is a css issue because when I inspect the page there is nothing inside the [[enter image description here](https://i.sstatic.net/itfVQp7j.png)](https://i.sstatic.net/2HNl7OM6.png)

2

Answers


  1. Chosen as BEST ANSWER

    The problem was I was missing the astrisk after the '/' in the path in the index.js file:

    <React.StrictMode>
    <BrowserRouter>
      <Routes>
        <Route path="/*" element={<App />} />
      </Routes>
    </BrowserRouter>
    

    </React.StrictMode>


  2. You should structure your code in a different way.

    In index.js:

    // ...
    
    root.render(
        <BrowserRouter>
            <App />
        </BrowserRouter>
    );
    

    You really don’t need to use two different Routes component (you are creating a Routes component with the App inside and then the App component has a Routes component too).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search