Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

108
Views
Unable to render two components from App.js

I am new to javascript and React. I am trying to render two components Layout and Home from App.js. When I tried rendering Layout component alone from App.js. Its working. But When I added Home component in App.js. Both are not working. Can anyone please help me out to resolve the issue. Below is my code

App.js

import './App.scss';
import { Routes, Route} from 'react-router-dom'
import React from 'react';
import Layout from './Components/Layout';
import Home from './Components/Home';

function App()
{
  return (
    <>
      <Routes>
      <Route path="/" element={<Layout />} />
      <Route index element={<Home />} />
         
      </Routes>
    </>
    )
}



export default App

Home.js


import LogoTitle from  '../../assets/images/logo-s.png'

const Home = () => {
    return (
        <div className="container home-page">
            <div className="text-zone">
                <hl>Hello World </h1>
            </div>
        </div>
    );
}


export default Home 
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Try some thing like. (index Route keep it nested)

function App() {
  return (
    <>
      <Routes>
        <Route path="/" element={<Layout />}>
          <Route index element={<Home />} />
        </Route>
      </Routes>
    </>
  );
}
about 4 years ago · Juan Pablo Isaza Report

0

You need to carefully read the react-router-dom documentation. According to the documentation,

  1. You must import {BrowserRouter as Router} from "react-router-dom".
  2. You must wrap everything you return inside element.
  3. You need to give every component a path to get that element on any action you're intended to get on.
import './App.scss';
import React from "react";
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
import Layout from './Components/Layout';
import Home from './Components/Home';

export default function App() {
  return (
    <Router>    
        <div>
            <Routes>
                 <Route path="/" element={<Layout />} />
                 <Route path="/Home" element={<Home />} />
            </Routes>
      </div>
    </Router>
  );
}


export default App
  1. If you want to get a specific component on some action e.g. on click, like inside home component, you first need to import { link } from "react-router-dom" and then use this as used in the code given below:
import LogoTitle from  '../../assets/images/logo-s.png'
import { link } from "react-router-dom"

const Home = () => {
    return (
        <Link to="/">Home</Link> //This must be inside your layout element, 
                                 //because this is your homepage for your 
                                 //website, according to how you have defined 
                                 //your routes.
    );
}


export default Home
about 4 years ago · Juan Pablo Isaza Report

0

try and run please this code block

function App()
{
  return (
    <>
      <Routes>
      <Route path="/layout " element={<Layout />} />
      <Route path="/home" element={<Home />} />
      </Routes>
    </>
    )
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!