So my website is gonna have three differently styled views for account types student, teacher and admin (its a dummy e-learning platform). I want to have a different styled navbar for student (two different versions for logged in and logged out) then a different one for teacher (again one for logged in and logged out) and then another one for admin(single one for logged in).
This is what Im doing right now. I made a layout component which warps everything.
const Layout: FC<LayoutProps> = (props) => {
return (
<div className="flex flex-col min-h-screen dark:bg-gray-800">
<MainNavigationBar />
<main className="mx-auto flex-grow" style={{ width: "90%" }}>
{props.children}
</main>
<Footer />
</div>
);
};
export default Layout;
Then this is what my App.tsx looks like.
export default function App() {
return (
<Layout>
<Routes>
<Route path="/" element={<HomePage />} />
<Route path="/signup" element={<SignUpPage />} />
<Route path="/login" element={<LogInPage />} />
<Route path="/cart" element={<EmptyCart />} />
<Route path="/cart/:studentId" element={<ShoppingCart />} />
<Route path="/checkout/:studentId" element={<CheckOutPage />} />
</Routes>
</Layout>
);
}
As you can see there are no routes for the teacher and admin yet because idk what is the best was to implement the functionality where each account type has different Navbar essentially meaning a totally different view style.
I have thought of two ways but help me understand which one is better.
- I put navbar directly inside each pages component. but that would mean that there will be copies of nav bar on each page for the account types and then updating changes would be hard, feels inefficent.
- I put all three nav bars in the App.tsx file and then conditionally render nav bar depending on which account type is active. this sounds better cause there will only be one nav bar copy per all account type pages. but problem with this is that idk how to trigger/set "account type active" when "/teacher" or "/admin" is visited.
Help me understand the best practice or technique, this is my first big project, thank you.