Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/app/lang-switcher/lang-switcher.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { NavLink, useLocation } from "react-router";
import { PAGES, type PagePair } from "../seo-links";

// Equivalent EN ↔ DE page pairs come from the single source of truth in
// seo-links.ts, so a page added there automatically works in the switcher too.
const pagePairs = Object.values(PAGES) as PagePair[];

function equivalentPaths(pathname: string): PagePair {
return (
pagePairs.find((p) => p.en === pathname || p.de === pathname) ??
PAGES.home
);
}

export function LangSwitcher() {
const { pathname } = useLocation();
const { en, de } = equivalentPaths(pathname);

return (
<div className="lang">
<NavLink
className={({ isActive }) =>
isActive ? "lang-left" : "not-active lang-left"
}
to={en}
end
>
en
</NavLink>
<NavLink
className={({ isActive }) =>
isActive ? "lang-right" : "not-active lang-right"
}
to={de}
end
>
de
</NavLink>
</div>
);
}
8 changes: 3 additions & 5 deletions src/app/routes/layout-de.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { Route } from "./+types/layout";
import { Imprint } from "../imprint/imprint";
import { NavLink, Outlet } from "react-router";
import { Outlet } from "react-router";
import { Footer } from "../footer/footer";
import { LangSwitcher } from "../lang-switcher/lang-switcher";

export function meta({}: Route.MetaArgs) {
return [
Expand All @@ -11,10 +12,7 @@ export function meta({}: Route.MetaArgs) {

export default function Layout() {
return (<><div className="navbar navbar-inverse navbar-fixed-top">
<div className="lang">
<NavLink className={({ isActive }) => isActive ? "lang-left" : "not-active lang-left"} to="/">en</NavLink>
<NavLink className={({ isActive }) => isActive ? "lang-right" : "not-active lang-right"} to="/de">de</NavLink>
</div>
<LangSwitcher />
</div>
<div className="container main-content">
<Outlet />
Expand Down
8 changes: 3 additions & 5 deletions src/app/routes/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { Route } from "./+types/layout";
import { Imprint } from "../imprint/imprint";
import { NavLink, Outlet } from "react-router";
import { Outlet } from "react-router";
import { Footer } from "../footer/footer";
import { LangSwitcher } from "../lang-switcher/lang-switcher";

export function meta({}: Route.MetaArgs) {
return [
Expand All @@ -11,10 +12,7 @@ export function meta({}: Route.MetaArgs) {

export default function Layout() {
return (<><div className="navbar navbar-inverse navbar-fixed-top">
<div className="lang">
<NavLink className={({ isActive }) => isActive ? "lang-left" : "not-active lang-left"} to="/">en</NavLink>
<NavLink className={({ isActive }) => isActive ? "lang-right" : "not-active lang-right"} to="/de">de</NavLink>
</div>
<LangSwitcher />
</div>
<div className="container main-content">
<Outlet />
Expand Down