Skip to content

Commit

Permalink
fix: types
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerlinsley committed Nov 18, 2022
1 parent 5d398ba commit 5b8b6f4
Show file tree
Hide file tree
Showing 13 changed files with 191 additions and 145 deletions.
10 changes: 5 additions & 5 deletions examples/react/basic-ssr-lite/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export const createRouter = () =>
// defaultPreload: 'intent',
})

declare module '@tanstack/react-router' {
interface RegisterRouter {
router: ReturnType<typeof createRouter>
}
}
// declare module '@tanstack/react-router' {
// interface RegisterRouter {
// router: ReturnType<typeof createRouter>
// }
// }
10 changes: 5 additions & 5 deletions examples/react/basic-ssr/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export const createRouter = () =>
// defaultPreload: 'intent',
})

declare module '@tanstack/react-router' {
interface RegisterRouter {
router: ReturnType<typeof createRouter>
}
}
// declare module '@tanstack/react-router' {
// interface RegisterRouter {
// router: ReturnType<typeof createRouter>
// }
// }
45 changes: 37 additions & 8 deletions examples/react/basic/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import {
createRouteConfig,
Link,
useMatch,
ResolvedRouter,
ResolvedAllRouteInfo,
RegisterRouter,
Router,
AnyAllRouteInfo,
RegisteredRouter,
} from '@tanstack/react-router'
import { TanStackRouterDevtools } from '@tanstack/react-router-devtools'

Expand Down Expand Up @@ -47,7 +43,17 @@ const PostsIndexRoute = postsRoute.createRoute({
})

const postRoute = postsRoute.createRoute({
path: ':postId',
path: 'post/:postId',
component: Post,
loader: async ({ params: { postId } }) => {
return {
post: await fetchPostById(postId),
}
},
})

const postDetailRoute = postRoute.createRoute({
path: 'detail',
component: Post,
loader: async ({ params: { postId } }) => {
return {
Expand All @@ -58,7 +64,10 @@ const postRoute = postsRoute.createRoute({

const routeConfig = createRouteConfig().addChildren([
indexRoute,
postsRoute.addChildren([PostsIndexRoute, postRoute]),
postsRoute.addChildren([
PostsIndexRoute,
postRoute.addChildren([postDetailRoute]),
]),
])

// Set up a ReactRouter instance
Expand Down Expand Up @@ -148,7 +157,7 @@ function Posts() {
return (
<div key={post.id}>
<Link
to="/posts/:postId"
to={postRoute.id}
params={{
postId: post.id,
}}
Expand Down Expand Up @@ -177,6 +186,7 @@ function PostsIndex() {
function Post() {
const {
loaderData: { post },
params: { postId },
} = useMatch(postRoute.id)

return (
Expand All @@ -187,6 +197,25 @@ function Post() {
)
}

function PostDetail() {
const {
loaderData: { post },
params: { postId },
} = useMatch(postDetailRoute.id)

const test = useMatch(postRoute.id, { strict: false })

test?.params.postId
// ^?

return (
<div>
<h4>{post.title}</h4>
<p>{post.body}</p>
</div>
)
}

const rootElement = document.getElementById('app')!
if (!rootElement.innerHTML) {
const root = ReactDOM.createRoot(rootElement)
Expand Down
10 changes: 5 additions & 5 deletions examples/react/kitchen-sink-codesplit/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export const router = createReactRouter({
),
})

declare module '@tanstack/react-router' {
interface RegisterRouter {
router: typeof router
}
}
// declare module '@tanstack/react-router' {
// interface RegisterRouter {
// router: typeof router
// }
// }
10 changes: 5 additions & 5 deletions examples/react/kitchen-sink-routegen/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export const router = createReactRouter({
),
})

declare module '@tanstack/react-router' {
interface RegisterRouter {
router: typeof router
}
}
// declare module '@tanstack/react-router' {
// interface RegisterRouter {
// router: typeof router
// }
// }
10 changes: 5 additions & 5 deletions examples/react/kitchen-sink/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ const router = createReactRouter({
),
})

declare module '@tanstack/react-router' {
interface RegisterRouter {
router: typeof router
}
}
// declare module '@tanstack/react-router' {
// interface RegisterRouter {
// router: typeof router
// }
// }

// Provide our location and routes to our application
function App() {
Expand Down
10 changes: 5 additions & 5 deletions examples/react/with-react-query/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ const router = createReactRouter({
defaultPreload: 'intent',
})

declare module '@tanstack/react-router' {
interface RegisterRouter {
router: typeof router
}
}
// declare module '@tanstack/react-router' {
// interface RegisterRouter {
// router: typeof router
// }
// }

const queryClient = new QueryClient()

Expand Down
14 changes: 5 additions & 9 deletions examples/react/with-trpc-react-query/client/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ const router = createReactRouter({
defaultPreload: 'intent',
})

declare module '@tanstack/react-router' {
interface RegisterRouter {
router: typeof router
}
}
// declare module '@tanstack/react-router' {
// interface RegisterRouter {
// router: typeof router
// }
// }

export const trpc = createTRPCReact<AppRouter>({})
function App() {
Expand Down Expand Up @@ -191,10 +191,6 @@ function Index() {

function Posts() {
const { Link } = useMatch(postsRoute.id)

const hello = trpc.hello
;({ text: 'client' })

const postsQuery = usePosts()

return (
Expand Down
10 changes: 5 additions & 5 deletions examples/react/with-trpc/client/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ const router = createReactRouter({
),
})

declare module '@tanstack/react-router' {
interface RegisterRouter {
router: typeof router
}
}
// declare module '@tanstack/react-router' {
// interface RegisterRouter {
// router: typeof router
// }
// }

// Provide our location and routes to our application
function App() {
Expand Down
Loading

0 comments on commit 5b8b6f4

Please sign in to comment.