Skip to content

Commit a9f0f26

Browse files
committed
Replaced window.location.href with Nextjs.router for fixing bug
1 parent 0f5bada commit a9f0f26

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

frontend/src/app/dashboard/page.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import { authAPI, pointsAPI } from '../../lib/api';
55
import { ThemeManager } from '../../utils/themeManager';
66
import { UnitManager } from '../../utils/unitManager';
77
import { formatTemperature, convertTemperature, getTemperatureForInput, convertTemperatureForStorage } from '../../utils/temperatureUtils';
8+
import { useRouter } from 'next/navigation';
89
import '../../styles/dashboard.css';
910

1011
export default function Dashboard() {
12+
const router = useRouter();
13+
1114
const [user, setUser] = useState(null);
1215
const [userPoints, setUserPoints] = useState([]);
1316
const [loading, setLoading] = useState(true);
@@ -86,7 +89,7 @@ export default function Dashboard() {
8689
const fetchUserData = async () => {
8790
try {
8891
if (!authAPI.isAuthenticated()) {
89-
window.location.href = '/';
92+
router.push('/');
9093
return;
9194
}
9295

@@ -137,7 +140,7 @@ export default function Dashboard() {
137140

138141
const handleLogout = () => {
139142
authAPI.logout();
140-
window.location.href = '/';
143+
router.push('/');
141144
};
142145

143146
// Get initials for avatar
@@ -291,7 +294,7 @@ export default function Dashboard() {
291294
if (response.success) {
292295
alert('Account deleted successfully');
293296
authAPI.logout();
294-
window.location.href = '/';
297+
router.push('/');
295298
} else {
296299
alert('Failed to delete account: ' + response.message);
297300
}
@@ -386,7 +389,7 @@ export default function Dashboard() {
386389
<h1 className='logotop' style={{ fontFamily: 'inter'}}>GLOW</h1>
387390
<h2 className='logobottom' style={{ fontFamily: 'inter'}}>by Microsofties</h2>
388391

389-
<div className="mapbut nav-item" onClick={() => window.location.href = '/'}>
392+
<div className="mapbut nav-item" onClick={() => router.push('/')}>
390393
<span>▶ Open Maps</span>
391394
</div>
392395

@@ -436,7 +439,7 @@ export default function Dashboard() {
436439
<h2 className='logobottom'>by Microsofties</h2>
437440
<div className="user-profile">
438441

439-
<div className="mapbut nav-item " onClick={() => window.location.href = '/'}
442+
<div className="mapbut nav-item " onClick={() => router.push('/')}
440443
>
441444
<span>▶ Open Maps </span>
442445
</div>
@@ -562,7 +565,7 @@ export default function Dashboard() {
562565
<div className="header-actions">
563566
<button
564567
className="add-btn"
565-
onClick={() => window.location.href = '/add-point?from=manage-points'}
568+
onClick={() => router.push('/add-point?from=manage-points')}
566569
>
567570
Add New Point
568571
</button>
@@ -577,7 +580,7 @@ export default function Dashboard() {
577580
<p>You haven't added any temperature points yet.</p>
578581
<button
579582
className="add-btn"
580-
onClick={() => window.location.href = '/add-point?from=manage-points'}
583+
onClick={() => router.push('/add-point?from=manage-points')}
581584
>
582585
Add Your First Point
583586
</button>

0 commit comments

Comments
 (0)