Skip to content

Commit

Permalink
feat(router-plugin): configurable key-based code splitting (#3355)
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanCassiere authored Feb 9, 2025
1 parent 026ea55 commit cf693e7
Show file tree
Hide file tree
Showing 520 changed files with 10,296 additions and 230 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export const Route = createFileRoute('/posts/$postId')({
return <p>Post not found</p>
},
component: PostComponent,
codeSplitGroupings: [
['component'],
['pendingComponent', 'errorComponent', 'notFoundComponent'],
],
})

export function PostErrorComponent({ error }: ErrorComponentProps) {
Expand Down
18 changes: 17 additions & 1 deletion e2e/react-router/basic-file-based-code-splitting/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,21 @@ import { TanStackRouterVite } from '@tanstack/router-plugin/vite'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [TanStackRouterVite({ autoCodeSplitting: true }), react()],
plugins: [
TanStackRouterVite({
autoCodeSplitting: true,
codeSplittingOptions: {
splitBehavior: ({ routeId }) => {
if (routeId === '/posts') {
return [
['loader'],
['component'],
['pendingComponent', 'notFoundComponent', 'errorComponent'],
]
}
},
},
}),
react(),
],
})
9 changes: 9 additions & 0 deletions packages/react-router/src/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,15 @@ export interface UpdatableRouteOptions<
meta?: AnyRouteMatch['meta']
}
ssr?: boolean
codeSplitGroupings?: Array<
Array<
| 'loader'
| 'component'
| 'pendingComponent'
| 'notFoundComponent'
| 'errorComponent'
>
>
}

export type RouteLoaderFn<
Expand Down
Loading

0 comments on commit cf693e7

Please sign in to comment.