-
-
Notifications
You must be signed in to change notification settings - Fork 793
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support errorComponent and pendingComponent code splitting
- Loading branch information
1 parent
17ac14c
commit d094028
Showing
9 changed files
with
281 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
examples/react/basic-file-based-codesplitting/src/routes/posts.$postId/errorComponent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import * as React from 'react' | ||
import { ErrorComponent, ErrorRouteProps } from '@tanstack/react-router' | ||
import { PostNotFoundError } from '../../posts' | ||
|
||
export const errorComponent = function PostErrorComponent({ | ||
error, | ||
}: ErrorRouteProps) { | ||
if (error instanceof PostNotFoundError) { | ||
return <div>{error.message}</div> | ||
} | ||
|
||
return <ErrorComponent error={error} /> | ||
} |
18 changes: 1 addition & 17 deletions
18
examples/react/basic-file-based-codesplitting/src/routes/posts.$postId/route.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,7 @@ | ||
import * as React from 'react' | ||
import { | ||
ErrorComponent, | ||
ErrorRouteProps, | ||
FileRoute, | ||
} from '@tanstack/react-router' | ||
import { PostNotFoundError } from '../../posts' | ||
import { FileRoute } from '@tanstack/react-router' | ||
|
||
export const Route = new FileRoute('/posts/$postId').createRoute({ | ||
errorComponent: PostErrorComponent, | ||
loaderDeps: () => ({ | ||
test: 'tanner' as const, | ||
}), | ||
loader: () => 'tanner', | ||
}) | ||
|
||
export function PostErrorComponent({ error }: ErrorRouteProps) { | ||
if (error instanceof PostNotFoundError) { | ||
return <div>{error.message}</div> | ||
} | ||
|
||
return <ErrorComponent error={error} /> | ||
} |
21 changes: 21 additions & 0 deletions
21
examples/react/basic-file-based-codesplitting/src/routes/posts_.$postId.deep.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import * as React from 'react' | ||
import { Link, RouteApi } from '@tanstack/react-router' | ||
|
||
const api = new RouteApi({ id: '/posts/$postId/deep' }) | ||
|
||
export const component = function PostDeepComponent() { | ||
const post = api.useLoaderData() | ||
|
||
return ( | ||
<div className="p-2 space-y-2"> | ||
<Link | ||
to="/posts" | ||
className="block py-1 text-blue-800 hover:text-blue-600" | ||
> | ||
← All Posts | ||
</Link> | ||
<h4 className="text-xl font-bold underline">{post.title}</h4> | ||
<div className="text-sm">{post.body}</div> | ||
</div> | ||
) | ||
} |
3 changes: 3 additions & 0 deletions
3
...es/react/basic-file-based-codesplitting/src/routes/posts_.$postId.deep.errorComponent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { errorComponent } from './posts.$postId/errorComponent' | ||
|
||
export { errorComponent } |
6 changes: 6 additions & 0 deletions
6
examples/react/basic-file-based-codesplitting/src/routes/posts_.$postId.deep.loader.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { FileRouteLoader } from '@tanstack/react-router' | ||
import { fetchPost } from '../posts' | ||
|
||
export const loader = FileRouteLoader('/posts/$postId/deep')( | ||
async ({ params: { postId } }) => fetchPost(postId), | ||
) |
27 changes: 0 additions & 27 deletions
27
examples/react/basic-file-based-codesplitting/src/routes/posts_.$postId.deep.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.