Просмотр исходного кода

🐛fix(HeaderBar): Prevent flicker when unauthenticated users click Console link

Previously, when an unauthenticated user clicked the "Console" navigation
link, the application would first attempt to navigate to '/console'.
This would then trigger a redirect to '/login', causing a brief flicker
between the two pages.

This commit modifies the `renderNavLinks` function in `HeaderBar.js`
to proactively check the user's authentication status. If the user is
not logged in and clicks the "Console" link, the navigation target
is directly set to '/login', avoiding the intermediate redirect and
eliminating the flickering effect.
Apple\Apple 9 месяцев назад
Родитель
Сommit
a726818c17
1 измененных файлов с 7 добавлено и 1 удалено
  1. 7 1
      web/src/components/HeaderBar.js

+ 7 - 1
web/src/components/HeaderBar.js

@@ -192,10 +192,16 @@ const HeaderBar = () => {
           </a>
           </a>
         );
         );
       }
       }
+
+      let targetPath = link.to;
+      if (link.itemKey === 'console' && !userState.user) {
+        targetPath = '/login';
+      }
+
       return (
       return (
         <Link
         <Link
           key={link.itemKey}
           key={link.itemKey}
-          to={link.to}
+          to={targetPath}
           className={commonLinkClasses}
           className={commonLinkClasses}
           onClick={() => handleNavLinkClick(link.itemKey)}
           onClick={() => handleNavLinkClick(link.itemKey)}
         >
         >