score:0

so my question is, is there any way i could do the same using my original folder structure. or more specifically, is thery any way i could do res.render(oneofthereactjsroutehere).

not really. if you're looking at server-side rendering of react then the usual approach is next.js (which means uses next.js' server and next.js' router).

but there is one particular case, i want to login as admin and set the session accordingly and again i can check if the admin is logged in using useeffect in frontend to fetch data from backend and do the things. but this will be tedious to in every reactjs page, as i have to check if admin is logged in many different pages.

that wouldn't help - since client side navigation would skip getting the route from the server.

abstract the logic into something reusable instead.

<route
    path="/admin"
    element={
      <requiresrole role="admin">
        <studentdashboard />
      </requiresrole>
    }
  />

and then have a component like

 const requiresrole = ({ role, children }) => {
     const roles = usemyauthenticationhook();
     if (!roles.includes(role)) {
         return /* a redirect to a login page or an error message or something */
     }

     return children;
 }

Related Query

More Query from same tag