Fix dashboard link and set up proper linking to avoid page reloads
This commit is contained in:
@@ -51,36 +51,20 @@ function App() {
|
|||||||
<Toaster richColors position="top-center" />
|
<Toaster richColors position="top-center" />
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route path="/login" element={<Login />} />
|
<Route path="/login" element={<Login />} />
|
||||||
<Route
|
{isLoggedIn ? (
|
||||||
path="/"
|
<Route element={<MainLayout />}>
|
||||||
element={
|
<Route path="/" element={<Dashboard />} />
|
||||||
isLoggedIn ? (
|
<Route path="/products" element={<Products />} />
|
||||||
<Navigate to="/dashboard" replace />
|
<Route path="/import" element={<Import />} />
|
||||||
) : (
|
<Route path="/orders" element={<Orders />} />
|
||||||
<Navigate to="/login" replace />
|
<Route path="/purchase-orders" element={<PurchaseOrders />} />
|
||||||
)
|
<Route path="/analytics" element={<Analytics />} />
|
||||||
}
|
<Route path="/settings" element={<Settings />} />
|
||||||
/>
|
<Route path="*" element={<Navigate to="/" replace />} />
|
||||||
<Route
|
</Route>
|
||||||
path="*"
|
) : (
|
||||||
element={
|
<Route path="*" element={<Navigate to="/login" replace />} />
|
||||||
isLoggedIn ? (
|
)}
|
||||||
<MainLayout>
|
|
||||||
<Routes>
|
|
||||||
<Route path="/" element={<Dashboard />} />
|
|
||||||
<Route path="/products" element={<Products />} />
|
|
||||||
<Route path="/import" element={<Import />} />
|
|
||||||
<Route path="/orders" element={<Orders />} />
|
|
||||||
<Route path="/purchase-orders" element={<PurchaseOrders />} />
|
|
||||||
<Route path="/analytics" element={<Analytics />} />
|
|
||||||
<Route path="/settings" element={<Settings />} />
|
|
||||||
</Routes>
|
|
||||||
</MainLayout>
|
|
||||||
) : (
|
|
||||||
<Navigate to="/login" replace />
|
|
||||||
)
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</Routes>
|
</Routes>
|
||||||
</QueryClientProvider>
|
</QueryClientProvider>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import {
|
|||||||
SidebarMenuItem,
|
SidebarMenuItem,
|
||||||
SidebarSeparator,
|
SidebarSeparator,
|
||||||
} from "@/components/ui/sidebar";
|
} from "@/components/ui/sidebar";
|
||||||
import { useLocation, useNavigate } from "react-router-dom";
|
import { useLocation, useNavigate, Link } from "react-router-dom";
|
||||||
|
|
||||||
const items = [
|
const items = [
|
||||||
{
|
{
|
||||||
@@ -86,12 +86,12 @@ export function AppSidebar() {
|
|||||||
tooltip={item.title}
|
tooltip={item.title}
|
||||||
isActive={isActive}
|
isActive={isActive}
|
||||||
>
|
>
|
||||||
<a href={item.url}>
|
<Link to={item.url}>
|
||||||
<item.icon className="h-4 w-4" />
|
<item.icon className="h-4 w-4" />
|
||||||
<span className="group-data-[collapsible=icon]:hidden">
|
<span className="group-data-[collapsible=icon]:hidden">
|
||||||
{item.title}
|
{item.title}
|
||||||
</span>
|
</span>
|
||||||
</a>
|
</Link>
|
||||||
</SidebarMenuButton>
|
</SidebarMenuButton>
|
||||||
</SidebarMenuItem>
|
</SidebarMenuItem>
|
||||||
);
|
);
|
||||||
@@ -110,12 +110,12 @@ export function AppSidebar() {
|
|||||||
tooltip="Settings"
|
tooltip="Settings"
|
||||||
isActive={location.pathname === "/settings"}
|
isActive={location.pathname === "/settings"}
|
||||||
>
|
>
|
||||||
<a href="/settings">
|
<Link to="/settings">
|
||||||
<Settings className="h-4 w-4" />
|
<Settings className="h-4 w-4" />
|
||||||
<span className="group-data-[collapsible=icon]:hidden">
|
<span className="group-data-[collapsible=icon]:hidden">
|
||||||
Settings
|
Settings
|
||||||
</span>
|
</span>
|
||||||
</a>
|
</Link>
|
||||||
</SidebarMenuButton>
|
</SidebarMenuButton>
|
||||||
</SidebarMenuItem>
|
</SidebarMenuItem>
|
||||||
</SidebarMenu>
|
</SidebarMenu>
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
import { SidebarProvider, SidebarTrigger } from "@/components/ui/sidebar";
|
import { SidebarProvider, SidebarTrigger } from "@/components/ui/sidebar";
|
||||||
import { AppSidebar } from "./AppSidebar";
|
import { AppSidebar } from "./AppSidebar";
|
||||||
|
import { Outlet } from "react-router-dom";
|
||||||
|
|
||||||
interface MainLayoutProps {
|
export function MainLayout() {
|
||||||
children: React.ReactNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function MainLayout({ children }: MainLayoutProps) {
|
|
||||||
return (
|
return (
|
||||||
<SidebarProvider defaultOpen>
|
<SidebarProvider defaultOpen>
|
||||||
<div className="flex min-h-screen w-full pr-2">
|
<div className="flex min-h-screen w-full pr-2">
|
||||||
@@ -13,9 +10,9 @@ export function MainLayout({ children }: MainLayoutProps) {
|
|||||||
<main className="flex-1 overflow-hidden">
|
<main className="flex-1 overflow-hidden">
|
||||||
<div className="flex h-14 w-full items-center border-b px-4 gap-4">
|
<div className="flex h-14 w-full items-center border-b px-4 gap-4">
|
||||||
<SidebarTrigger />
|
<SidebarTrigger />
|
||||||
</div>
|
</div>
|
||||||
<div className="overflow-auto h-[calc(100vh-3.5rem)] max-w-[1500px]">
|
<div className="overflow-auto h-[calc(100vh-3.5rem)] max-w-[1500px]">
|
||||||
{children}
|
<Outlet />
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user