1- import React from 'react' ;
1+ import React , { useState , useEffect } from 'react' ;
22import { SettingsProvider } from './stores/settingsStore' ;
33import { AuthProvider , useAuth } from './stores/authStore' ;
44import { Navigation } from './components/Navigation' ;
@@ -12,9 +12,24 @@ import './styles.css';
1212
1313const AppContent : React . FC = ( ) => {
1414 const { isAuthenticated, isLoading } = useAuth ( ) ;
15+ const [ currentHash , setCurrentHash ] = useState ( window . location . hash . slice ( 1 ) || '/' ) ;
1516
16- // Simple routing based on hash
17- const currentHash = window . location . hash . slice ( 1 ) || '/' ;
17+ // Handle hash changes without page reload
18+ useEffect ( ( ) => {
19+ const handleHashChange = ( ) => {
20+ setCurrentHash ( window . location . hash . slice ( 1 ) || '/' ) ;
21+ } ;
22+
23+ window . addEventListener ( 'hashchange' , handleHashChange ) ;
24+ return ( ) => window . removeEventListener ( 'hashchange' , handleHashChange ) ;
25+ } , [ ] ) ;
26+
27+ // Redirect to dashboard when authenticated and on login/register pages
28+ useEffect ( ( ) => {
29+ if ( isAuthenticated && ( currentHash === '/login' || currentHash === '/register' ) ) {
30+ window . location . hash = '/dashboard' ;
31+ }
32+ } , [ isAuthenticated , currentHash ] ) ;
1833
1934 const renderPage = ( ) => {
2035 if ( isLoading ) {
@@ -59,17 +74,6 @@ const AppContent: React.FC = () => {
5974 }
6075 } ;
6176
62- // Update navigation links to use hash routing
63- React . useEffect ( ( ) => {
64- const handleHashChange = ( ) => {
65- // Force re-render when hash changes
66- window . location . reload ( ) ;
67- } ;
68-
69- window . addEventListener ( 'hashchange' , handleHashChange ) ;
70- return ( ) => window . removeEventListener ( 'hashchange' , handleHashChange ) ;
71- } , [ ] ) ;
72-
7377 return (
7478 < SettingsProvider >
7579 < div className = "min-h-screen bg-gray-50" >
0 commit comments