@@ -12,13 +12,13 @@ export function bind(node) {
1212 } ;
1313}
1414
15- export function History ( { onHistoryChange } ) {
15+ export function History ( { onHistoryChangeCallback } ) {
1616 // Capture browser "history go back" action and tell the server about it
1717 // Note: Browsers do not allow us to detect "history go forward" actions.
1818 React . useEffect ( ( ) => {
1919 // Register a listener for the "popstate" event and send data back to the server using the `onHistoryChange` callback.
2020 const listener = ( ) => {
21- onHistoryChange ( {
21+ onHistoryChangeCallback ( {
2222 pathname : window . location . pathname ,
2323 search : window . location . search ,
2424 } ) ;
@@ -34,29 +34,29 @@ export function History({ onHistoryChange }) {
3434 // Tell the server about the URL during the initial page load
3535 // FIXME: This currently runs every time any component is mounted due to a ReactPy core rendering bug.
3636 // https://github.com/reactive-python/reactpy/pull/1224
37- React . useEffect ( ( ) => {
38- onHistoryChange ( {
39- pathname : window . location . pathname ,
40- search : window . location . search ,
41- } ) ;
42- return ( ) => { } ;
43- } , [ ] ) ;
37+ // React.useEffect(() => {
38+ // onHistoryChange({
39+ // pathname: window.location.pathname,
40+ // search: window.location.search,
41+ // });
42+ // return () => {};
43+ // }, []);
4444 return null ;
4545}
4646
4747// FIXME: The Link component is unused due to a ReactPy core rendering bug
4848// which causes duplicate rendering (and thus duplicate event listeners).
4949// https://github.com/reactive-python/reactpy/pull/1224
50- export function Link ( { onClick , linkClass } ) {
50+ export function Link ( { onClickCallback , linkClass } ) {
5151 // This component is not the actual anchor link.
5252 // It is an event listener for the link component created by ReactPy.
5353 React . useEffect ( ( ) => {
5454 // Event function that will tell the server about clicks
5555 const handleClick = ( event ) => {
5656 event . preventDefault ( ) ;
5757 let to = event . target . getAttribute ( "href" ) ;
58- window . history . pushState ( { } , to , new URL ( to , window . location ) ) ;
59- onClick ( {
58+ window . history . pushState ( null , "" , new URL ( to , window . location ) ) ;
59+ onClickCallback ( {
6060 pathname : window . location . pathname ,
6161 search : window . location . search ,
6262 } ) ;
@@ -78,3 +78,20 @@ export function Link({ onClick, linkClass }) {
7878 } ) ;
7979 return null ;
8080}
81+
82+ export function Navigate ( { onNavigateCallback, to, replace } ) {
83+ React . useEffect ( ( ) => {
84+ if ( replace ) {
85+ window . history . replaceState ( null , "" , new URL ( to , window . location ) ) ;
86+ } else {
87+ window . history . pushState ( null , "" , new URL ( to , window . location ) ) ;
88+ }
89+ onNavigateCallback ( {
90+ pathname : window . location . pathname ,
91+ search : window . location . search ,
92+ } ) ;
93+ return ( ) => { } ;
94+ } , [ ] ) ;
95+
96+ return null ;
97+ }
0 commit comments