-
-
Notifications
You must be signed in to change notification settings - Fork 574
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e43f26f
commit b27f649
Showing
53 changed files
with
521 additions
and
1,163 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
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
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
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
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
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,20 +1,10 @@ | ||
import * as React from 'react' | ||
import ReactDOM from 'react-dom/client' | ||
|
||
import { App } from '.' | ||
import { router } from './router' | ||
import { loaderClient } from './loaderClient' | ||
import { StartClient } from '@tanstack/react-start/client' | ||
import { createRouter } from './router' | ||
|
||
const { dehydratedRouter, dehydratedLoaderClient } = (window as any) | ||
.__TSR_DEHYDRATED__ | ||
const router = createRouter() | ||
router.hydrate() | ||
|
||
// Hydrate the loader client first | ||
loaderClient.hydrate(dehydratedLoaderClient) | ||
|
||
// Hydrate the router next | ||
router.hydrate(dehydratedRouter) | ||
|
||
ReactDOM.hydrateRoot( | ||
document, | ||
<App router={router} loaderClient={loaderClient} head={''} />, | ||
) | ||
ReactDOM.hydrateRoot(document, <StartClient router={router} />) |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,57 @@ | ||
import { RegisteredLoaderClient } from '@tanstack/react-loaders' | ||
import { Router } from '@tanstack/router' | ||
import { loaderClient } from './loaderClient' | ||
import { routeTree } from './routeTree' | ||
import { LoaderClientProvider } from '@tanstack/react-loaders' | ||
|
||
export interface RouterContext { | ||
loaderClient: RegisteredLoaderClient | ||
import { rootRoute } from './routes/root' | ||
import { indexRoute } from './routes/index' | ||
import { postsRoute } from './routes/posts' | ||
import { postsIndexRoute } from './routes/posts/index' | ||
import { postIdRoute } from './routes/posts/$postId' | ||
|
||
import { createLoaderClient } from './loaderClient' | ||
import React from 'react' | ||
|
||
export type RouterContext = { | ||
loaderClient: ReturnType<typeof createLoaderClient> | ||
head: string | ||
} | ||
|
||
export const router = new Router({ | ||
routeTree, | ||
context: { | ||
loaderClient, | ||
}, | ||
}) | ||
export const routeTree = rootRoute.addChildren([ | ||
indexRoute, | ||
postsRoute.addChildren([postsIndexRoute, postIdRoute]), | ||
]) | ||
|
||
export function createRouter() { | ||
const loaderClient = createLoaderClient() | ||
|
||
return new Router({ | ||
routeTree, | ||
context: { | ||
loaderClient, | ||
head: '', | ||
}, | ||
// On the server, dehydrate the loader client | ||
dehydrate: () => { | ||
return { | ||
loaderClient: loaderClient.dehydrate(), | ||
} | ||
}, | ||
// On the client, rehydrate the loader client | ||
hydrate: (dehydrated) => { | ||
loaderClient.hydrate(dehydrated.loaderClient) | ||
}, | ||
// Wrap our router in the loader client provider | ||
Wrap: ({ children }) => { | ||
return ( | ||
<LoaderClientProvider loaderClient={loaderClient}> | ||
{children} | ||
</LoaderClientProvider> | ||
) | ||
}, | ||
}) | ||
} | ||
|
||
declare module '@tanstack/router' { | ||
interface Register { | ||
router: typeof router | ||
router: ReturnType<typeof createRouter> | ||
} | ||
} |
Oops, something went wrong.