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

154
Views
React router nested routing is not working

I am using react router v6 and trying to nest routers to switch only a particular div of the page.

I tried doing this

<div className="user-profile-page">
    <div className="user-profile-page-background">
        <img className="full-img" src = {user.profile_picture_url} />
    </div>
    <div className = "user-profile-contents-container">
        <h1 className="user-profile-name ellipsis">{user.full_name} ({user.age})</h1>
        <div className = "user-profile-nav">
            <NavLink to = "" className={(state)=>!state.isActive?"user-profile-nav-item":"user-profile-nav-item user-profile-nav-item-active"}>
                About
            </NavLink>
            <NavLink to = "pictures" className={(state)=>!state.isActive?"user-profile-nav-item":"user-profile-nav-item user-profile-nav-item-active"}>
                Pictures
            </NavLink>
        </div>
        <div className = "user-profile-contents-main">
            <Routes>
                <Route index={true} element = {<UserProfileAbout />} />
                <Route path = "pictures" element =  {<UserProfilePictures />} />
            </Routes>
        </div>
    </div>
</div>

but when I go to "/user/pictures" instead of just changing the contents inside "user-profile-contents-main" div. It changes the whole page.

Here is my main router

<Routes>
    <Route path = "/" element = {<HomePage /> } />
    <Route path = "/message/:uid" element = {<ChatPage />} />
    <Route path = "/user/:uid" element = {<UserProfilePage />} />
</Routes>

EDIT

all i had to do was

<Routes>
    <Route path = "/" element = {<HomePage /> } />
    <Route path = "/message/:uid" element = {<ChatPage />} />
    <Route path = "/user/:uid/*" element = {<UserProfilePage />} />
</Routes>

add /* in the route path

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

 <Routes>
    <Route index={true} element = {<UserProfileAbout />} />
    <Route path = "pictures" element =  {<UserProfilePictures />} />
 </Routes>

no need to declare a new navigation inside the component in which it should be called, if you want to isolate some screens it is better to create a separate stack for them

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!