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

23 lines
576 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-12 17:13:41 +02:00
import { RouteMatch } from './RouteMatch'
2024-05-11 16:08:51 +02:00
import NotFound from './NotFound'
2024-05-11 15:08:49 +02:00
2024-05-14 21:23:32 +02:00
interface MatchesProps {
serverPath?: string
}
export function Matches({ serverPath }: MatchesProps): JSX.Element {
2024-05-11 15:08:49 +02:00
const location = useRouterStore((st) => st.location)
const router = useRouter()
2024-05-14 21:23:32 +02:00
const route = router.routesById[location?.pathname || serverPath || '']
2024-05-11 15:08:49 +02:00
2024-05-11 16:08:51 +02:00
if (!route) {
return <NotFound />
}
2024-05-12 17:13:41 +02:00
return <RouteMatch route={route} />
2024-05-14 21:23:32 +02:00
}