Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to render components inside a container in a page based on links pressed – ReactJs

I have a page called Teacher.js which is supposed to hold content related to that teacher. I have a sidebar having different links like profile, information etc. I want if a user presses suppose profile, the profile component to load on the right side of the sidebar just any website would do. I am new to react. what should I do?

what I want more clearly:

So I want if some presses suppose profile I want the profile component to render in the highlighted blue area where "this is the main content" is written

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

So if someone presses suppose profile, I want the profile component to render in the highlighted blue area where "this is the main content" is written

>Solution :

Add a routing library to your project, such as react-router. Then have the parent render the sidebar and the main content should be rendered using the router.

Inside the sidebar, each section should then just be a link to the correct route.

It would look something like this:

export const TeacherContainer = () => {
  return (
    <div>
      <Sidebar />
      <Routes>
        <Route path="profile" element={<TeacherProfile />}>
        <Route path="info" element={<TeacherInformation />}>
        // etc.
      </Routes>
    </div>
  );
};
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading