11import { createMemo , onMount } from "solid-js" ;
2- import { createFileRoute } from "@tanstack/solid-router" ;
2+ import { createFileRoute , notFound } from "@tanstack/solid-router" ;
33import { fetchPackageData } from "~/api.js" ;
4+ import NotFound from "~/components/NotFound.jsx" ;
45import { PRIMITIVE_PAGE_PADDING_TOP } from "~/components/Header/Header.jsx" ;
56import InfoBar from "~/components/Primitives/InfoBar.jsx" ;
67import { H2 } from "~/components/prose.jsx" ;
@@ -13,9 +14,26 @@ import { createPrimitiveNameTooltips } from "./-components/primitive-name-toolti
1314
1415export const Route = createFileRoute ( "/package/$name/" ) ( {
1516 component : PackagePage ,
16- loader : async ( { params } ) => fetchPackageData ( params . name ) ,
17- head : ( { params } ) => ( {
18- meta : [ { title : `${ kebabCaseToCapitalized ( params . name ) } — Solid Primitives` } ] ,
17+ // Handle unknown package names (e.g. /package/wefwe) with the same 404 page
18+ // as any other missing route. We throw `notFound()` from the loader when the
19+ // dynamic JSON import fails, and a route-level `notFoundComponent` catches
20+ // it so TanStack doesn't need to walk up to the (absent) root handler.
21+ notFoundComponent : NotFound ,
22+ loader : async ( { params } ) => {
23+ try {
24+ return await fetchPackageData ( params . name ) ;
25+ } catch {
26+ throw notFound ( ) ;
27+ }
28+ } ,
29+ head : ( { params, loaderData } ) => ( {
30+ meta : [
31+ {
32+ title : loaderData
33+ ? `${ kebabCaseToCapitalized ( params . name ) } — Solid Primitives`
34+ : "Not Found — Solid Primitives" ,
35+ } ,
36+ ] ,
1937 } ) ,
2038} ) ;
2139
0 commit comments