MCPcopy Create free account
hub / github.com/github/docs / ClientSideRedirects

Function ClientSideRedirects

components/ClientSideRedirects.tsx:12–43  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10)
11
12export function ClientSideRedirects() {
13 const { asPath } = useRouter()
14 // We have some one-off redirects for rest api docs
15 // currently those are limited to the repos page, but
16 // that will grow soon as we restructure the rest api docs.
17 // This is a workaround to updating the hardcoded links
18 // directly in the REST API code in a separate repo, which
19 // requires many file changes and teams to sign off.
20 // While the organization is turbulent, we can do this.
21 // Once it's more settled, we can refactor the rest api code
22 // to leverage the OpenAPI urls rather than hardcoded urls.
23 // The code below determines if we should bother loading this redirecting
24 // component at all.
25 // The reason this isn't done at the server-level is because there you
26 // can't possibly access the URL hash. That's only known in client-side
27 // code.
28 const [load, setLoad] = useState(false)
29 useEffect(() => {
30 const { hash } = window.location
31
32 // Today, Jan 2022, it's known explicitly what the pathname.
33 // In the future there might be more.
34 // Hopefully, we can some day delete all of this and no longer
35 // be dependent on the URL hash to do the redirect.
36 if (hash && asPath.startsWith('/rest')) {
37 setLoad(true)
38 }
39 }, [])
40
41 if (load) return <ClientSideRedirectExceptions />
42 return null
43}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected