@@ -3,76 +3,24 @@ import {
33 redirect ,
44 notFound ,
55 createFileRoute ,
6- lazyRouteComponent ,
76} from '@tanstack/react-router'
8- import type { AsyncRouteComponent } from '@tanstack/react-router'
9- import type { ReactNode } from 'react'
107import { RedirectVersionBanner } from '~/components/RedirectVersionBanner'
11- import { findLibrary , getBranch } from '~/libraries'
12- import type { LibraryId } from '~/libraries'
13- import { getTanstackDocsConfig } from '~/utils/config'
14- import { fetchLandingCodeExample } from '~/utils/landing-code-example.functions'
8+ import { findLibrary } from '~/libraries'
9+ import { loadLibraryConfig , validateLibraryVersion } from '../-library-landing'
1510
16- export type LandingComponentProps = {
17- landingCodeExampleRsc ?: ReactNode
18- }
19-
20- export const landingComponents : Partial <
21- Record < LibraryId , AsyncRouteComponent < LandingComponentProps > >
22- > = {
23- query : lazyRouteComponent ( ( ) => import ( '~/components/landing/QueryLanding' ) ) ,
24- router : lazyRouteComponent (
25- ( ) => import ( '~/components/landing/RouterLanding' ) ,
26- ) ,
27- table : lazyRouteComponent ( ( ) => import ( '~/components/landing/TableLanding' ) ) ,
28- form : lazyRouteComponent ( ( ) => import ( '~/components/landing/FormLanding' ) ) ,
29- start : lazyRouteComponent ( ( ) => import ( '~/components/landing/StartLanding' ) ) ,
30- store : lazyRouteComponent ( ( ) => import ( '~/components/landing/StoreLanding' ) ) ,
31- virtual : lazyRouteComponent (
32- ( ) => import ( '~/components/landing/VirtualLanding' ) ,
33- ) ,
34- ranger : lazyRouteComponent (
35- ( ) => import ( '~/components/landing/RangerLanding' ) ,
36- ) ,
37- pacer : lazyRouteComponent ( ( ) => import ( '~/components/landing/PacerLanding' ) ) ,
38- hotkeys : lazyRouteComponent (
39- ( ) => import ( '~/components/landing/HotkeysLanding' ) ,
40- ) ,
41- config : lazyRouteComponent (
42- ( ) => import ( '~/components/landing/ConfigLanding' ) ,
43- ) ,
44- db : lazyRouteComponent ( ( ) => import ( '~/components/landing/DbLanding' ) ) ,
45- ai : lazyRouteComponent ( ( ) => import ( '~/components/landing/AiLanding' ) ) ,
46- devtools : lazyRouteComponent (
47- ( ) => import ( '~/components/landing/DevtoolsLanding' ) ,
48- ) ,
49- cli : lazyRouteComponent ( ( ) => import ( '~/components/landing/CliLanding' ) ) ,
50- intent : lazyRouteComponent (
51- ( ) => import ( '~/components/landing/IntentLanding' ) ,
52- ) ,
53- }
11+ export type { LandingComponentProps } from '../-library-landing'
5412
5513export const Route = createFileRoute ( '/$libraryId/$version' ) ( {
5614 staleTime : 1000 * 60 * 5 ,
5715 beforeLoad : async ( ctx ) => {
5816 const { libraryId, version } = ctx . params
59- const library = findLibrary ( libraryId )
60-
61- if ( ! library ) {
62- throw notFound ( )
63- }
64-
65- library . handleRedirects ?.( ctx . location . href )
66-
67- if ( ! library . availableVersions . concat ( 'latest' ) . includes ( version ! ) ) {
17+ const library = validateLibraryVersion ( libraryId , version , ( ) => {
6818 throw redirect ( {
6919 params : { libraryId, version : 'latest' } as never ,
7020 } )
71- }
21+ } )
7222
73- if ( ! ctx . location . pathname . includes ( '/docs' ) ) {
74- await landingComponents [ libraryId as LibraryId ] ?. preload ?.( )
75- }
23+ library . handleRedirects ?.( ctx . location . href )
7624 } ,
7725 loader : async ( ctx ) => {
7826 const { libraryId, version } = ctx . params
@@ -82,26 +30,8 @@ export const Route = createFileRoute('/$libraryId/$version')({
8230 throw notFound ( )
8331 }
8432
85- const branch = getBranch ( library , version )
86- const config = await getTanstackDocsConfig ( {
87- data : {
88- repo : library . repo ,
89- branch,
90- docsRoot : library . docsRoot || 'docs' ,
91- } ,
92- } )
93-
94- const landingCodeExample = ctx . location . pathname . includes ( '/docs' )
95- ? null
96- : await fetchLandingCodeExample ( {
97- data : {
98- libraryId,
99- } ,
100- } )
101-
10233 return {
103- config,
104- landingCodeExampleRsc : landingCodeExample ?. contentRsc ?? null ,
34+ config : await loadLibraryConfig ( library . id , version ! ) ,
10535 }
10636 } ,
10737 component : RouteForm ,
0 commit comments