diff --git a/src/hooks/router.tsx b/src/hooks/router.tsx index 7f025aa..e1bccf4 100644 --- a/src/hooks/router.tsx +++ b/src/hooks/router.tsx @@ -133,6 +133,7 @@ export function useParamsRequired< shape, children, onValidationError, + onValidationSuccess = () => {}, validateOptions, }: { shape: Shape @@ -142,6 +143,11 @@ export function useParamsRequired< >, ) => ReactNode onValidationError: (navigate: Navigate) => void + onValidationSuccess?: ( + params: NonNullable< + TryValidateSyncRT, OnErrorRT> + >, + ) => void validateOptions?: TryValidateSyncOptions< ObjectSchemaFromShape, OnErrorRT @@ -151,8 +157,9 @@ export function useParamsRequired< const navigate = useNavigate() useEffect(() => { - if (!params) onValidationError(navigate) - }, [params, onValidationError, navigate]) + if (params) onValidationSuccess(params) + else onValidationError(navigate) + }, [params, onValidationSuccess, onValidationError, navigate]) return params ? children(params) : <> }