diff --git a/ui/src/components/Layout.tsx b/ui/src/components/Layout.tsx
index 28773668..c918dcb5 100644
--- a/ui/src/components/Layout.tsx
+++ b/ui/src/components/Layout.tsx
@@ -1,7 +1,7 @@
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useQuery } from "@tanstack/react-query";
import { BookOpen, MessageSquare, Moon, Settings, Sun } from "lucide-react";
-import { Link, Outlet, useLocation, useNavigate, useParams } from "@/lib/router";
+import { Link, Navigate, Outlet, useLocation, useNavigate, useParams } from "@/lib/router";
import { CompanyRail } from "./CompanyRail";
import { Sidebar } from "./Sidebar";
import { InstanceSidebar } from "./InstanceSidebar";
@@ -460,10 +460,31 @@ export function Layout() {
)}
>
{hasUnknownCompanyPrefix ? (
-
+ // [nexus] Auto-recover from bogus URL prefixes by redirecting
+ // to the same path under the first available company, instead
+ // of leaving the user stranded on an "Invite not available"
+ // style dead end with no way back. hasUnknownCompanyPrefix is
+ // already gated on companies.length > 0, so the fallback is
+ // guaranteed to resolve. If no fallback exists for some reason,
+ // fall through to the old NotFoundPage.
+ (() => {
+ const fallbackCompany = selectedCompany ?? companies[0] ?? null;
+ if (!fallbackCompany) {
+ return (
+
+ );
+ }
+ const restOfPath = location.pathname.replace(/^\/[^/]+/, "") || "/dashboard";
+ return (
+
+ );
+ })()
) : (
)}