11<script lang =" ts" >
22import { onMount } from ' svelte' ;
33
4- export const fallbackPath: string = ' /' ;
5- export const showText: boolean = true ;
6- export const customClass: string = ' ' ;
4+ export let fallbackPath: string = ' /' ;
5+ export let showText: boolean = true ;
6+ export let customClass: string = ' ' ;
77// Hide button on these paths (home by default)
8- export const hideOnPaths: string [] = [' /' ];
8+ export let hideOnPaths: string [] = [' /' ];
99
1010let _isVisible = true ;
1111
@@ -27,13 +27,25 @@ function _goBack() {
2727 }
2828}
2929
30+ // Initialize visibility immediately
31+ updateVisibility ();
32+
3033onMount (() => {
34+ // Update visibility again on mount in case window object is ready
3135 updateVisibility ();
32- window .addEventListener (' popstate' , updateVisibility );
33- window .addEventListener (' hashchange' , updateVisibility );
36+
37+ const handleVisibilityUpdate = () => {
38+ updateVisibility ();
39+ // Force Svelte to re-render by updating a reactive variable
40+ _isVisible = _isVisible ; // This triggers reactivity
41+ };
42+
43+ window .addEventListener (' popstate' , handleVisibilityUpdate );
44+ window .addEventListener (' hashchange' , handleVisibilityUpdate );
45+
3446 return () => {
35- window .removeEventListener (' popstate' , updateVisibility );
36- window .removeEventListener (' hashchange' , updateVisibility );
47+ window .removeEventListener (' popstate' , handleVisibilityUpdate );
48+ window .removeEventListener (' hashchange' , handleVisibilityUpdate );
3749 };
3850});
3951 </script >
0 commit comments