(props: OrgSlugGateProps)
| 39 | } |
| 40 | |
| 41 | export function OrgSlugGate(props: OrgSlugGateProps) { |
| 42 | const { activeSlug } = props; |
| 43 | const params = useParams({ strict: false }) as { orgSlug?: string }; |
| 44 | const urlSlug = params.orgSlug ?? null; |
| 45 | const navigate = useNavigate(); |
| 46 | |
| 47 | // Skip canonicalization whenever the router is currently sitting on a |
| 48 | // not-found match — see the file header for why. |
| 49 | const isNotFound = useRouterState({ |
| 50 | select: (state) => state.matches.some((match) => match._notFound), |
| 51 | }); |
| 52 | |
| 53 | const needsCanonicalize = urlSlug !== activeSlug && !isNotFound; |
| 54 | |
| 55 | useEffect(() => { |
| 56 | if (!needsCanonicalize) return; |
| 57 | // Re-target the CURRENT route with the active slug. `to: "."` + |
| 58 | // `search: true` keeps path and query (deep links like |
| 59 | // `/integrations/add/mcp?url=…` canonicalize in place); only the orgSlug |
| 60 | // param changes. |
| 61 | void navigate({ |
| 62 | to: ".", |
| 63 | params: (previous: Record<string, string>) => ({ ...previous, orgSlug: activeSlug }), |
| 64 | search: true, |
| 65 | replace: true, |
| 66 | }); |
| 67 | }, [needsCanonicalize, activeSlug, navigate]); |
| 68 | |
| 69 | // Render through while canonicalizing — the target is the same route, so |
| 70 | // withholding children would only flash the page. |
| 71 | return <>{props.children}</>; |
| 72 | } |
nothing calls this directly
no outgoing calls
no test coverage detected