Backups
diff --git a/beszel/site/src/components/router.tsx b/beszel/site/src/components/router.tsx
index a76745d..968bc45 100644
--- a/beszel/site/src/components/router.tsx
+++ b/beszel/site/src/components/router.tsx
@@ -1,16 +1,36 @@
import { createRouter } from "@nanostores/router"
-export const $router = createRouter(
- {
- home: "/",
- server: "/system/:name",
- settings: "/settings/:name?",
- forgot_password: "/forgot-password",
- },
- { links: false }
-)
+const routes = {
+ home: "/",
+ system: `/system/:name`,
+ settings: `/settings/:name?`,
+ forgot_password: `/forgot-password`,
+} as const
-/** Navigate to url using router */
+/**
+ * The base path of the application.
+ * This is used to prepend the base path to all routes.
+ */
+export const basePath = window.BASE_PATH || ""
+
+/**
+ * Prepends the base path to the given path.
+ * @param path The path to prepend the base path to.
+ * @returns The path with the base path prepended.
+ */
+export const prependBasePath = (path: string) => (basePath + path).replaceAll("//", "/")
+
+// prepend base path to routes
+for (const route in routes) {
+ // @ts-ignore need as const above to get nanostores to parse types properly
+ routes[route] = prependBasePath(routes[route])
+}
+
+export const $router = createRouter(routes, { links: false })
+
+/** Navigate to url using router
+ * Base path is automatically prepended if serving from subpath
+ */
export const navigate = (urlString: string) => {
$router.open(urlString)
}
diff --git a/beszel/site/src/components/routes/home.tsx b/beszel/site/src/components/routes/home.tsx
index be2121f..f38e1fb 100644
--- a/beszel/site/src/components/routes/home.tsx
+++ b/beszel/site/src/components/routes/home.tsx
@@ -7,8 +7,9 @@ import { Separator } from "../ui/separator"
import { alertInfo, updateRecordList, updateSystemList } from "@/lib/utils"
import { AlertRecord, SystemRecord } from "@/types"
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
-import { Link } from "../router"
+import { $router, Link } from "../router"
import { Plural, t, Trans } from "@lingui/macro"
+import { getPagePath } from "@nanostores/router"
const SystemsTable = lazy(() => import("../systems-table/systems-table"))
@@ -83,7 +84,7 @@ export default function Home() {
diff --git a/beszel/site/src/components/routes/settings/layout.tsx b/beszel/site/src/components/routes/settings/layout.tsx
index 8c50556..a23ff19 100644
--- a/beszel/site/src/components/routes/settings/layout.tsx
+++ b/beszel/site/src/components/routes/settings/layout.tsx
@@ -4,7 +4,7 @@ import { SidebarNav } from "./sidebar-nav.tsx"
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card.tsx"
import { useStore } from "@nanostores/react"
import { $router } from "@/components/router.tsx"
-import { redirectPage } from "@nanostores/router"
+import { getPagePath, redirectPage } from "@nanostores/router"
import { BellIcon, FileSlidersIcon, SettingsIcon } from "lucide-react"
import { $userSettings, pb } from "@/lib/stores.ts"
import { toast } from "@/components/ui/use-toast.ts"
@@ -49,17 +49,17 @@ export default function SettingsLayout() {
const sidebarNavItems = [
{
title: _(t({ message: `General`, comment: "Context: General settings" })),
- href: "/settings/general",
+ href: getPagePath($router, "settings", { name: "general" }),
icon: SettingsIcon,
},
{
title: t`Notifications`,
- href: "/settings/notifications",
+ href: getPagePath($router, "settings", { name: "notifications" }),
icon: BellIcon,
},
{
title: t`YAML Config`,
- href: "/settings/config",
+ href: getPagePath($router, "settings", { name: "config" }),
icon: FileSlidersIcon,
admin: true,
},
@@ -69,8 +69,8 @@ export default function SettingsLayout() {
useEffect(() => {
document.title = t`Settings` + " / Beszel"
- // redirect to account page if no page is specified
- if (page?.path === "/settings") {
+ // @ts-ignore redirect to account page if no page is specified
+ if (!page?.params?.name) {
redirectPage($router, "settings", { name: "general" })
}
}, [])
diff --git a/beszel/site/src/components/routes/settings/notifications.tsx b/beszel/site/src/components/routes/settings/notifications.tsx
index 3b73f5b..183b3d1 100644
--- a/beszel/site/src/components/routes/settings/notifications.tsx
+++ b/beszel/site/src/components/routes/settings/notifications.tsx
@@ -13,6 +13,7 @@ import { saveSettings } from "./layout"
import * as v from "valibot"
import { isAdmin } from "@/lib/utils"
import { Trans, t } from "@lingui/macro"
+import { prependBasePath } from "@/components/router"
interface ShoutrrrUrlCardProps {
url: string
@@ -94,7 +95,7 @@ const SettingsNotificationsPage = ({ userSettings }: { userSettings: UserSetting
Please{" "}
-
+
configure an SMTP server
{" "}
to ensure alerts are delivered.
diff --git a/beszel/site/src/components/routes/settings/sidebar-nav.tsx b/beszel/site/src/components/routes/settings/sidebar-nav.tsx
index 8690e9b..3ee7aad 100644
--- a/beszel/site/src/components/routes/settings/sidebar-nav.tsx
+++ b/beszel/site/src/components/routes/settings/sidebar-nav.tsx
@@ -22,7 +22,7 @@ export function SidebarNav({ className, items, ...props }: SidebarNavProps) {
<>
{/* Mobile View */}
-