Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix(router): inherit params for named project routes (#20512)

boojack37d9997f32e3
diff --git a/frontend/src/react/router/currentRouteSnapshot.test.ts b/frontend/src/react/router/currentRouteSnapshot.test.ts
index 0f75a94efe..2806f1a2b4 100644
--- a/frontend/src/react/router/currentRouteSnapshot.test.ts
+++ b/frontend/src/react/router/currentRouteSnapshot.test.ts
@@ -1,5 +1,41 @@
-import { describe, expect, it } from "vitest";
+import { beforeEach, describe, expect, it, vi } from "vitest";
+import {
+ PROJECT_V1_ROUTE_WEBHOOK_CREATE,
+ PROJECT_V1_ROUTE_WEBHOOK_DETAIL,
+ PROJECT_V1_ROUTE_WEBHOOKS,
+} from "./handles";
import { router } from "./index";
+import { setAppRouter, setRouteNameIndex } from "./navigation";
+
+beforeEach(() => {
+ setRouteNameIndex(
+ new Map<string, string>([
+ [PROJECT_V1_ROUTE_WEBHOOKS, "/projects/:projectId/webhooks"],
+ [PROJECT_V1_ROUTE_WEBHOOK_CREATE, "/projects/:projectId/webhooks/new"],
+ [
+ PROJECT_V1_ROUTE_WEBHOOK_DETAIL,
+ "/projects/:projectId/webhooks/:webhookResourceId",
+ ],
+ ])
+ );
+ setAppRouter({
+ navigate: vi.fn(),
+ state: {
+ location: {
+ pathname: "/projects/project-sample/webhooks",
+ search: "",
+ hash: "",
+ },
+ matches: [
+ {
+ handle: { name: PROJECT_V1_ROUTE_WEBHOOKS },
+ params: { projectId: "project-sample" },
+ },
+ ],
+ initialized: true,
+ },
+ });
+});
// Guardrail for the "getSnapshot should be cached" infinite-loop class.
// `router.currentRoute.value` backs the `useReactiveRoute` `useSyncExternalStore`
@@ -15,3 +51,17 @@ describe("router.currentRoute snapshot stability", () => {
expect(a).toBe(b);
});
});
+
+describe("router named route params", () => {
+ it("inherits current params when resolving project child routes", () => {
+ expect(
+ router.resolve({ name: PROJECT_V1_ROUTE_WEBHOOK_CREATE }).fullPath
+ ).toBe("/projects/project-sample/webhooks/new");
+ expect(
+ router.resolve({
+ name: PROJECT_V1_ROUTE_WEBHOOK_DETAIL,
+ params: { webhookResourceId: "hook-1" },
+ }).fullPath
+ ).toBe("/projects/project-sample/webhooks/hook-1");
+ });
+});
diff --git a/frontend/src/react/router/index.ts b/frontend/src/react/router/index.ts
index 16279ae955..d6da390a34 100644
--- a/frontend/src/react/router/index.ts
+++ b/frontend/src/react/router/index.ts
@@ -108,7 +108,10 @@ function resolveTarget(to: RouteTarget): string {
: `#${to.hash}`
: "";
if (to.name) {
- return `${resolvePath(to.name, { params: to.params, query: to.query })}${hash}`;
+ return `${resolvePath(to.name, {
+ params: inheritCurrentParams(to.params),
+ query: to.query,
+ })}${hash}`;
}
if (to.path) {
const search = to.query ? buildSearchString(to.query) : "";
@@ -127,6 +130,18 @@ function resolveTarget(to: RouteTarget): string {
return `${search ? `${path}?${search}` : path}${hash}`;
}
+function inheritCurrentParams(
+ params: Record<string, string | string[] | undefined> | undefined
+): Record<string, string | string[] | undefined> {
+ const merged = { ...currentRouteSnapshot().params };
+ for (const [key, value] of Object.entries(params ?? {})) {
+ if (value !== undefined) {
+ merged[key] = value;
+ }
+ }
+ return merged;
+}
+
// Shared builder for both the `useCurrentRoute` hook and the non-hook
// `router.currentRoute.value` snapshot, so the two stay shape-identical.
// Exported as `buildReactRoute` for the app root's leave-guard blocker, which