Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/react/navigation-blocking/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const fooRoute = createRoute({
getParentRoute: () => rootRoute,
path: 'foo/$id',
validateSearch: (search) => ({ hello: search.hello }) as { hello: string },
component: () => <>foo {fooRoute.useParams().id}</>,
component: () => <div>foo {fooRoute.useParams().id}</div>,
})

const editor1Route = createRoute({
Expand Down
19 changes: 2 additions & 17 deletions examples/react/start-basic/src/routes/__root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import {
HeadContent,
Link,
Outlet,
Scripts,
createRootRoute,
} from '@tanstack/react-router'
Expand Down Expand Up @@ -58,25 +57,11 @@ export const Route = createRootRoute({
},
],
}),
errorComponent: (props) => {
return (
<RootDocument>
<DefaultCatchBoundary {...props} />
</RootDocument>
)
},
errorComponent: DefaultCatchBoundary,
notFoundComponent: () => <NotFound />,
component: RootComponent,
shellComponent: RootDocument,
})

function RootComponent() {
return (
<RootDocument>
<Outlet />
</RootDocument>
)
}

function RootDocument({ children }: { children: React.ReactNode }) {
return (
<html>
Expand Down
19 changes: 2 additions & 17 deletions examples/solid/start-basic/src/routes/__root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import {
HeadContent,
Link,
Outlet,
Scripts,
createRootRoute,
} from '@tanstack/solid-router'
Expand Down Expand Up @@ -52,25 +51,11 @@ export const Route = createRootRoute({
{ rel: 'icon', href: '/favicon.ico' },
],
}),
errorComponent: (props) => {
return (
<RootDocument>
<DefaultCatchBoundary {...props} />
</RootDocument>
)
},
errorComponent: DefaultCatchBoundary,
notFoundComponent: () => <NotFound />,
component: RootComponent,
shellComponent: RootDocument,
})

function RootComponent() {
return (
<RootDocument>
<Outlet />
</RootDocument>
)
}

function RootDocument({ children }: { children: Solid.JSX.Element }) {
return (
<>
Expand Down
13 changes: 10 additions & 3 deletions packages/react-router/src/Match.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import { matchContext } from './matchContext'
import { SafeFragment } from './SafeFragment'
import { renderRouteNotFound } from './renderRouteNotFound'
import { ScrollRestoration } from './scroll-restoration'
import type { AnyRoute, ParsedLocation } from '@tanstack/router-core'
import type {
AnyRoute,
ParsedLocation,
RootRouteOptions,
} from '@tanstack/router-core'

export const Match = React.memo(function MatchImpl({
matchId,
Expand Down Expand Up @@ -80,8 +84,11 @@ export const Match = React.memo(function MatchImpl({
},
})

const ShellComponent = route.isRoot
? ((route.options as RootRouteOptions).shellComponent ?? SafeFragment)
: SafeFragment
return (
<>
<ShellComponent>
<matchContext.Provider value={matchId}>
<ResolvedSuspenseBoundary fallback={pendingElement}>
<ResolvedCatchBoundary
Expand Down Expand Up @@ -119,7 +126,7 @@ export const Match = React.memo(function MatchImpl({
<ScrollRestoration />
</>
) : null}
</>
</ShellComponent>
)
})

Expand Down
3 changes: 1 addition & 2 deletions packages/react-router/src/Matches.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type {
StructuralSharingOption,
ValidateSelected,
} from './structuralSharing'
import type { ReactNode } from './route'
import type {
AnyRouter,
DeepPartial,
Expand Down Expand Up @@ -154,7 +153,7 @@ export type MakeMatchRouteOptions<
TRouter['routeTree'],
ResolveRelativePath<TFrom, NoInfer<TTo>>
>['types']['allParams'],
) => ReactNode)
) => React.ReactNode)
| React.ReactNode
}

Expand Down
1 change: 0 additions & 1 deletion packages/react-router/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ export {
} from './route'
export type {
AnyRootRoute,
ReactNode,
SyncRouteComponent,
AsyncRouteComponent,
RouteComponent,
Expand Down
14 changes: 10 additions & 4 deletions packages/react-router/src/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ declare module '@tanstack/router-core' {
pendingComponent?: RouteComponent
}

export interface RootRouteOptionsExtensions {
shellComponent?: ({
children,
}: {
children: React.ReactNode
}) => React.ReactNode
}

export interface RouteExtensions<
in out TId extends string,
in out TFullPath extends string,
Expand Down Expand Up @@ -534,11 +542,9 @@ export function createRouteMask<
return opts as any
}

export type ReactNode = any

export type SyncRouteComponent<TProps> =
| ((props: TProps) => ReactNode)
| React.LazyExoticComponent<(props: TProps) => ReactNode>
| React.FC<TProps>
| React.LazyExoticComponent<(props: TProps) => React.ReactNode>

export type AsyncRouteComponent<TProps> = SyncRouteComponent<TProps> & {
preload?: () => Promise<void>
Expand Down
2 changes: 2 additions & 0 deletions packages/react-router/tests/router.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,7 @@ describe('search params in URL', () => {
validateSearch,
errorComponent: ({ error }) => {
errorSpy = error
return null
},
})

Expand All @@ -1477,6 +1478,7 @@ describe('search params in URL', () => {
validateSearch,
errorComponent: ({ error }) => {
errorSpy = error
return null
},
})

Expand Down
1 change: 1 addition & 0 deletions packages/router-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export type {
RouteContextOptions,
BeforeLoadContextOptions,
RootRouteOptions,
RootRouteOptionsExtensions,
UpdatableRouteOptionsExtensions,
RouteConstraints,
RouteTypesById,
Expand Down
10 changes: 9 additions & 1 deletion packages/router-core/src/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,13 @@ export interface LoaderFnContext<
route: AnyRoute
}

export interface DefaultRootRouteOptionsExtensions {
shellComponent?: unknown
}

export interface RootRouteOptionsExtensions
extends DefaultRootRouteOptionsExtensions {}

export type RootRouteOptions<
TSearchValidator = undefined,
TRouterContext = {},
Expand Down Expand Up @@ -1234,7 +1241,8 @@ export type RootRouteOptions<
| 'parseParams'
| 'stringifyParams'
| 'params'
>
> &
RootRouteOptionsExtensions

export type RouteConstraints = {
TParentRoute: AnyRoute
Expand Down
10 changes: 7 additions & 3 deletions packages/solid-router/src/Match.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { matchContext } from './matchContext'
import { SafeFragment } from './SafeFragment'
import { renderRouteNotFound } from './renderRouteNotFound'
import { ScrollRestoration } from './scroll-restoration'
import type { AnyRoute } from '@tanstack/router-core'
import type { AnyRoute, RootRouteOptions } from '@tanstack/router-core'

export const Match = (props: { matchId: string }) => {
const router = useRouter()
Expand Down Expand Up @@ -77,8 +77,12 @@ export const Match = (props: { matchId: string }) => {
},
})

const ShellComponent = route().isRoot
? ((route().options as RootRouteOptions).shellComponent ?? SafeFragment)
: SafeFragment

return (
<>
<ShellComponent>
<matchContext.Provider value={() => props.matchId}>
<Dynamic
component={ResolvedSuspenseBoundary()}
Expand Down Expand Up @@ -124,7 +128,7 @@ export const Match = (props: { matchId: string }) => {
<ScrollRestoration />
</>
) : null}
</>
</ShellComponent>
)
}

Expand Down
8 changes: 8 additions & 0 deletions packages/solid-router/src/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ declare module '@tanstack/router-core' {
pendingComponent?: RouteComponent
}

export interface RootRouteOptionsExtensions {
shellComponent?: ({
children,
}: {
children: Solid.JSX.Element
}) => Solid.JSX.Element
}

export interface RouteExtensions<
in out TId extends string,
in out TFullPath extends string,
Expand Down