Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

fix loading bug

Bill Yangc4ae9aba99ba
diff --git a/client/src/app/[site]/layout.tsx b/client/src/app/[site]/layout.tsx
index 44b08e1b4..b678e8565 100644
--- a/client/src/app/[site]/layout.tsx
+++ b/client/src/app/[site]/layout.tsx
@@ -29,7 +29,6 @@ export default function SiteLayout({
return (
<>
<Header />
-
{children}
</>
);
diff --git a/client/src/app/[site]/page.tsx b/client/src/app/[site]/page.tsx
index 793c817f5..10d53cc8d 100644
--- a/client/src/app/[site]/page.tsx
+++ b/client/src/app/[site]/page.tsx
@@ -1,17 +1,44 @@
-"use client";
-import { useEffect } from "react";
-import { useRouter, useParams } from "next/navigation";
+import { redirect } from "next/navigation";
+import { Suspense } from "react";
-export default function SiteRedirect() {
- const router = useRouter();
- const params = useParams();
+// Temporary loading component that will show while the redirect is processing
+function Loading() {
+ return (
+ <div className="min-h-screen flex items-center justify-center">
+ <div className="text-center">
+ <div className="inline-block w-12 h-12 border-4 border-blue-500 border-t-transparent rounded-full animate-spin"></div>
+ <p className="mt-4">Redirecting to dashboard...</p>
+ </div>
+ </div>
+ );
+}
+
+// This is now a Server Component (no "use client" directive)
+export default function SiteRedirect({ params }: { params: { site: string } }) {
const siteId = params.site;
- useEffect(() => {
- if (siteId) {
- router.replace(`/${siteId}/main`);
- }
- }, [siteId, router]);
+ if (siteId) {
+ // Server-side redirect using Next.js redirect function
+ redirect(`/${siteId}/main`);
+ }
- return null;
+ // This code will not execute if redirect is successful
+ return (
+ <Suspense fallback={<Loading />}>
+ <div className="min-h-screen flex items-center justify-center">
+ <div className="text-center">
+ <h1 className="text-xl font-bold mb-4">Redirect Failed</h1>
+ <p className="mb-4">Unable to navigate to the dashboard.</p>
+ {siteId && (
+ <a
+ href={`/${siteId}/main`}
+ className="px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700 inline-block"
+ >
+ Go to Dashboard
+ </a>
+ )}
+ </div>
+ </div>
+ </Suspense>
+ );
}
diff --git a/client/src/middleware.ts b/client/src/middleware.ts
new file mode 100644
index 000000000..d4931ea89
--- /dev/null
+++ b/client/src/middleware.ts
@@ -0,0 +1,24 @@
+import { NextResponse } from "next/server";
+import type { NextRequest } from "next/server";
+
+export function middleware(request: NextRequest) {
+ const url = request.nextUrl.clone();
+ const path = url.pathname;
+
+ // Check if we're on the exact site route (nothing after site name)
+ const siteRoutePattern = /^\/([^/]+)$/;
+ const match = path.match(siteRoutePattern);
+
+ if (match) {
+ const siteId = match[1];
+ // Redirect to the main page for this site
+ return NextResponse.redirect(new URL(`/${siteId}/main`, request.url));
+ }
+
+ return NextResponse.next();
+}
+
+// Only run middleware on specific paths to avoid unnecessary execution
+export const config = {
+ matcher: "/:site",
+};