@module-federation/bridge-react
Advanced tools
Comparing version 0.0.0-next-20240909092952 to 0.0.0-next-20240909101028
# @module-federation/bridge-react | ||
## 0.0.0-next-20240909092952 | ||
## 0.0.0-next-20240909101028 | ||
### Patch Changes | ||
- @module-federation/bridge-shared@0.0.0-next-20240909092952 | ||
- chore: bump next | ||
- @module-federation/bridge-shared@0.0.0-next-20240909101028 | ||
## 0.6.1 | ||
### Patch Changes | ||
- @module-federation/bridge-shared@0.6.1 | ||
## 0.6.0 | ||
@@ -10,0 +17,0 @@ |
@@ -180,3 +180,3 @@ "use strict"; | ||
}; | ||
RemoteApp2["__APP_VERSION__"] = "0.6.0"; | ||
RemoteApp2["__APP_VERSION__"] = "0.6.1"; | ||
return /* @__PURE__ */ React.createElement(RemoteApp2, null); | ||
@@ -403,3 +403,35 @@ }); | ||
} | ||
function useBridgeRouteChange(onRouteChange) { | ||
const previousUrlRef = React.useRef(window.location.pathname); | ||
React.useEffect(() => { | ||
const handleRouteChange = () => { | ||
const currentUrl = window.location.pathname; | ||
const from = previousUrlRef.current; | ||
const to = currentUrl; | ||
if (from !== to) { | ||
onRouteChange({ from, to }); | ||
previousUrlRef.current = currentUrl; | ||
} | ||
}; | ||
const originalPushState = window.history.pushState; | ||
const originalReplaceState = window.history.replaceState; | ||
window.history.pushState = function(...args) { | ||
originalPushState.apply(window.history, args); | ||
handleRouteChange(); | ||
}; | ||
window.history.replaceState = function(...args) { | ||
console.log("<<<<< replaceState called >>>>>>>", args); | ||
originalReplaceState.apply(window.history, args); | ||
handleRouteChange(); | ||
}; | ||
window.addEventListener("popstate", handleRouteChange); | ||
return () => { | ||
window.history.pushState = originalPushState; | ||
window.history.replaceState = originalReplaceState; | ||
window.removeEventListener("popstate", handleRouteChange); | ||
}; | ||
}, [onRouteChange]); | ||
} | ||
exports.createBridgeComponent = createBridgeComponent; | ||
exports.createRemoteComponent = createRemoteComponent; | ||
exports.useBridgeRouteChange = useBridgeRouteChange; |
@@ -69,2 +69,7 @@ import { ComponentType } from 'react'; | ||
export declare function useBridgeRouteChange(onRouteChange: ({ from, to }: { | ||
from: string; | ||
to: string; | ||
}) => void): void; | ||
export { } |
@@ -161,3 +161,3 @@ import * as React from "react"; | ||
}; | ||
RemoteApp2["__APP_VERSION__"] = "0.6.0"; | ||
RemoteApp2["__APP_VERSION__"] = "0.6.1"; | ||
return /* @__PURE__ */ React__default.createElement(RemoteApp2, null); | ||
@@ -384,5 +384,37 @@ }); | ||
} | ||
function useBridgeRouteChange(onRouteChange) { | ||
const previousUrlRef = useRef(window.location.pathname); | ||
useEffect(() => { | ||
const handleRouteChange = () => { | ||
const currentUrl = window.location.pathname; | ||
const from = previousUrlRef.current; | ||
const to = currentUrl; | ||
if (from !== to) { | ||
onRouteChange({ from, to }); | ||
previousUrlRef.current = currentUrl; | ||
} | ||
}; | ||
const originalPushState = window.history.pushState; | ||
const originalReplaceState = window.history.replaceState; | ||
window.history.pushState = function(...args) { | ||
originalPushState.apply(window.history, args); | ||
handleRouteChange(); | ||
}; | ||
window.history.replaceState = function(...args) { | ||
console.log("<<<<< replaceState called >>>>>>>", args); | ||
originalReplaceState.apply(window.history, args); | ||
handleRouteChange(); | ||
}; | ||
window.addEventListener("popstate", handleRouteChange); | ||
return () => { | ||
window.history.pushState = originalPushState; | ||
window.history.replaceState = originalReplaceState; | ||
window.removeEventListener("popstate", handleRouteChange); | ||
}; | ||
}, [onRouteChange]); | ||
} | ||
export { | ||
createBridgeComponent, | ||
createRemoteComponent | ||
createRemoteComponent, | ||
useBridgeRouteChange | ||
}; |
{ | ||
"name": "@module-federation/bridge-react", | ||
"version": "0.0.0-next-20240909092952", | ||
"version": "0.0.0-next-20240909101028", | ||
"publishConfig": { | ||
@@ -38,3 +38,3 @@ "access": "public" | ||
"react-error-boundary": "^4.0.13", | ||
"@module-federation/bridge-shared": "0.0.0-next-20240909092952" | ||
"@module-federation/bridge-shared": "0.0.0-next-20240909101028" | ||
}, | ||
@@ -41,0 +41,0 @@ "peerDependencies": { |
export { createRemoteComponent } from './create'; | ||
export { createBridgeComponent } from './provider'; | ||
export { useBridgeRouteChange } from './hooks'; | ||
export type { | ||
@@ -4,0 +5,0 @@ ProviderParams, |
91717
38
2473
+ Added@module-federation/bridge-shared@0.0.0-next-20240909101028(transitive)
- Removed@module-federation/bridge-shared@0.0.0-next-20240909092952(transitive)
Updated@module-federation/bridge-shared@0.0.0-next-20240909101028