@tanstack/react-router 0.0.1-beta.79 → 0.0.1-beta.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/index.js +4 -4
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.js +4 -4
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +55 -55
- package/build/types/index.d.ts +3 -3
- package/build/umd/index.development.js +4 -4
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +3 -3
- package/src/index.tsx +8 -5
package/src/index.tsx
CHANGED
|
@@ -133,7 +133,7 @@ declare module '@tanstack/router' {
|
|
|
133
133
|
|
|
134
134
|
export type PromptProps = {
|
|
135
135
|
message: string
|
|
136
|
-
|
|
136
|
+
condition?: boolean | any
|
|
137
137
|
children?: ReactNode
|
|
138
138
|
}
|
|
139
139
|
|
|
@@ -719,11 +719,14 @@ export function ErrorComponent({ error }: { error: any }) {
|
|
|
719
719
|
)
|
|
720
720
|
}
|
|
721
721
|
|
|
722
|
-
export function useBlocker(
|
|
722
|
+
export function useBlocker(
|
|
723
|
+
message: string,
|
|
724
|
+
condition: boolean | any = true,
|
|
725
|
+
): void {
|
|
723
726
|
const router = useRouter()
|
|
724
727
|
|
|
725
728
|
React.useEffect(() => {
|
|
726
|
-
if (!
|
|
729
|
+
if (!condition) return
|
|
727
730
|
|
|
728
731
|
let unblock = router.history.block((retry, cancel) => {
|
|
729
732
|
if (window.confirm(message)) {
|
|
@@ -738,7 +741,7 @@ export function useBlocker(message: string, when: boolean | any = true): void {
|
|
|
738
741
|
})
|
|
739
742
|
}
|
|
740
743
|
|
|
741
|
-
export function Block({ message,
|
|
742
|
-
useBlocker(message,
|
|
744
|
+
export function Block({ message, condition, children }: PromptProps) {
|
|
745
|
+
useBlocker(message, condition)
|
|
743
746
|
return (children ?? null) as ReactNode
|
|
744
747
|
}
|