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

101
Views
React.js what is the best technique to show to the user different pages according to there role

there a sec or two that the wrong page appears on the screen until the request get me the user's role so i can show him the right page. how can i show them the right page since the first moment

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

0

The best way is to handle the role is App.js File because all your route are there and then you can specifiy which route should be avalible according to thier roles.like this example:

// App.js 
function App() {
const [addUserManagment, setAddUserManagment] = useState({
   render: false,
   type: "",
});
useEffect(() => {
   const space = localStorage.getItem("space");
   if (space === "c" || space === "a") {
   setAddUserManagment({
      render: true,
      type: space,
   });
  }
}, []);
  return (
<div className="App">
  <Routes>
    <Route path="/">
      <Route index element={<Login />} />
      <Route path="forget-password" element={<ForgetPassword />} />
      <Route path="reset-password/:token" element={<RestPassword />} />
      <Route
        path="register/:campanyName/:companyId"
        element={<InviteRegister />}
      />
    </Route>
          <Route path="profile" element={<Profile />} />
      {addUserManagment.render && (
        <Route path="setting" element={<Setting />} />
      )}
      {addUserManagment.render && (
        <Route
          path="user-management"
          element={
            addUserManagment.type === "c" ? <UserList /> : <UserListAdmin />
          }
        />
      )}
    </Route>
   </Routes>
  )
}

Now settign and user-managment are rendered if type of user equal to c or a.

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!