Files
tuono/packages/tuono-router/src/components/Matches.tsx
T

40 lines
824 B
TypeScript
Raw Normal View History

2024-05-11 15:08:49 +02:00
import * as React from 'react'
import { useRouter } from '../hooks/useRouter'
import { useRouterStore } from '../hooks/useRouterStore'
2024-05-11 16:08:51 +02:00
import NotFound from './NotFound'
2024-05-11 15:08:49 +02:00
export function Matches(): JSX.Element | undefined {
const matchId = useRouterStore.getState().matches[0]?.id
//if (!matchId) return <></>
return (
<React.Suspense>
<Match id={matchId} />
</React.Suspense>
)
}
interface MatchProps {
id: string
}
const Match = React.memo(function ({ id }: MatchProps) {
const location = useRouterStore((st) => st.location)
const router = useRouter()
console.log(router, location)
const route = router.routesById[location?.pathname]
2024-05-11 16:08:51 +02:00
if (!route) {
return <NotFound />
}
if (route.options.hasHandler) {
console.log('Has rust handler')
}
2024-05-11 15:08:49 +02:00
return route.component()
})