- `.html`-Endungen werden nun automatisch für Menüeinträge hinzugefügt, wenn die App in der Produktionsumgebung läuft. - Verwendung von `process.env.NODE_ENV`, um die Umgebung zu prüfen und die Pfade entsprechend anzupassen. - Verbesserung der Kompatibilität mit statischen Dateien nach dem Build.
50 lines
1.4 KiB
JavaScript
50 lines
1.4 KiB
JavaScript
"use client"; // components/Navigation.jsx
|
|
import React, { useEffect, useState } from "react";
|
|
import Link from "next/link";
|
|
import { usePathname } from "next/navigation";
|
|
|
|
function Navigation() {
|
|
const pathname = usePathname();
|
|
const [activeLink, setActiveLink] = useState("");
|
|
|
|
useEffect(() => {
|
|
if (pathname) {
|
|
setActiveLink(pathname);
|
|
}
|
|
}, [pathname]);
|
|
|
|
// Funktion, die das ".html" basierend auf der Umgebung hinzufügt
|
|
const formatPath = (path) => {
|
|
return process.env.NODE_ENV === "production" ? `${path}.html` : path;
|
|
};
|
|
|
|
// Menüeinträge ohne .html-Endungen für die Entwicklungsumgebung
|
|
const menuItems = [
|
|
{ name: "Übersicht", path: "/dashboard" },
|
|
{ name: "Kabelüberwachung", path: "/kabelueberwachung" },
|
|
// Weitere Menüpunkte hier
|
|
];
|
|
|
|
return (
|
|
<aside>
|
|
<nav className="w-64 flex-shrink-0 mt-32 overflow-hidden">
|
|
{menuItems.map((item) => (
|
|
<Link href={formatPath(item.path)} key={item.name}>
|
|
<div
|
|
className={`block px-4 py-2 mb-4 font-bold whitespace-nowrap transition duration-300 ${
|
|
activeLink.startsWith(item.path)
|
|
? "bg-sky-500 text-white rounded-r-full"
|
|
: "text-black hover:bg-gray-200 rounded-r-full"
|
|
}`}
|
|
>
|
|
{item.name}
|
|
</div>
|
|
</Link>
|
|
))}
|
|
</nav>
|
|
</aside>
|
|
);
|
|
}
|
|
|
|
export default Navigation;
|