Skip to content

Commit

Permalink
Stricter route prop types
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe committed Mar 19, 2021
1 parent 3ce3133 commit b4c7469
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions packages/router/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,34 @@ type PageType =
| ((props: any) => JSX.Element)

interface RouteProps {
path?: string
page?: PageType
name?: string
notfound?: boolean
redirect?: string
path: string
page: PageType
name: string
prerender?: boolean
whileLoading?: () => React.ReactElement | null
}

const Route: React.VFC<RouteProps> = ({
interface RedirectRouteProps {
path: string
redirect: string
}

interface NotFoundRouteProps {
notfound: boolean
page: PageType
}

type InternalRouteProps = Partial<
RouteProps & RedirectRouteProps & NotFoundRouteProps
>

const Route: React.VFC<RouteProps | RedirectRouteProps | NotFoundRouteProps> = (
props
) => {
return <InternalRoute {...props} />
}

const InternalRoute: React.VFC<InternalRouteProps> = ({
path,
page,
name,
Expand Down Expand Up @@ -165,7 +183,7 @@ const Private: React.FC<PrivateProps> = ({

function isRoute(
node: React.ReactNode
): node is React.ReactElement<RouteProps> {
): node is React.ReactElement<InternalRouteProps> {
return isReactElement(node) && node.type === Route
}

Expand Down

0 comments on commit b4c7469

Please sign in to comment.