From NavBar Mess to React Router Success! Fixing Layouts, Routing & AIOHA in One Go πŸš€

By sagarkothari88 on 7/29/2025

πŸ› οΈ From NavBar Mess to React Router Success! πŸ˜‚

Hello Hive Community πŸ‘‹,


🎯 Today’s Mission (Impossible?)

  1. Fix the broken NavBar 😡
  2. Integrate navigation using react-router-dom’s <Link>
  3. Create a layout to avoid repeating NavBar on every page

πŸͺ› Fixing the NavBar Bug

Image from post" alt="buggy nav bar">

See this monstrosity above? 😱 That’s what we got even though we copied the beautiful DaisyUI navbar. πŸ€”
After a LOT of head-scratching and a few cups of chai β˜•...

one little silly mistake

Boom! Found it β€” I forgot to import daisyui in app.css 🀦
One small import for me, one giant leap for NavBar!


🧩 Updated NavBar Component

import React from "react";
import HiveUserAvatarButton from "./HiveUserAvatarButton";

const NavBar = () => {
  return (
    <div className="navbar bg-base-100 shadow-sm">
      <div className="flex-1">
        <a className="btn btn-ghost text-xl">Distriator</a>
      </div>
      <div className="flex-none">
        <HiveUserAvatarButton />
      </div>
    </div>
  );
};

export default NavBar;

Notice we’re using a fancy new HiveUserAvatarButton component πŸ‘‡


πŸ§‘β€πŸš€ Custom AIOHA Login Button

Regular Login Primary Button

Time to ditch that boring default button.
Let’s use our custom-built login avatar button that:

  • Shows a Login button if user is not logged in
  • Displays avatar if logged in βœ…
import { useState } from "react";
import { useAioha, AiohaModal } from "@aioha/react-ui";
import { KeyTypes } from "@aioha/aioha";
import "@aioha/react-ui/dist/build.css";

const HiveUserAvatarButton = () => {
  const [modalDisplayed, setModalDisplayed] = useState(false);
  const { user } = useAioha();

  function userAvatarBasedButton() {
    return (
      <div className="avatar" onClick={() => setModalDisplayed(true)}>
        <div className="w-10 rounded-full overflow-hidden">
          <img src={`https://images.hive.blog/u/${user}/avatar`} />
        </div>
      </div>
    );
  }

  function loginButton() {
    return (<button className="btn btn-primary" onClick={() => setModalDisplayed(true)}>Login</button>);
  }

  function aiohaModel() {
    return (
      <div>
        <AiohaModal
          displayed={modalDisplayed}
          loginOptions={{
            msg: "Login",
            keyType: KeyTypes.Posting,
          }}
          onLogin={console.log}
          onClose={setModalDisplayed}
        />
      </div>
    );
  }

  return (
    <>
      {user ? userAvatarBasedButton() : loginButton()}
      {aiohaModel()}
    </>
  );
};

export default HiveUserAvatarButton;

🧱 Let’s Build a Common Layout

Because... DRY (Don’t Repeat Yourself) πŸ˜…

import React from 'react'
import NavBar from './NavBar'

const CommonLayout = ({children}) => {
  return (
    <>
      <div>
        <NavBar />
      </div>
      <main>{children}</main>
    </>
  );
}

export default CommonLayout;

πŸŽ‰ Now every page can reuse this layout with the NavBar already baked in.


πŸ“„ Using the Common Layout on a Page

import React from 'react'
import CommonLayout from '../../Components/CommonLayout'

const AboutUsPage = () => {
  return (
    <CommonLayout>
      <div>AboutUsPage</div>
    </CommonLayout>
  )
}

export default AboutUsPage;

🧭 Add Nav Links for Navigation

Time to give our NavBar a promotion by adding About Us & Contact Us links!

Daisy Documentation

Thank you DaisyUI for making this super easy. Just βœ‚οΈ copy & paste...

Update NavBar


πŸ”— Use React Router’s <Link> β€” No More <a>

react router link

Replace all old-school <a href> with <Link to> from react-router-dom β€”
That way, no page refreshes and smooth routing FTW ⚑


πŸ§‘β€πŸ’» Final Words

Today’s work may look small but helped build strong foundation for the app.

  • βœ… NavBar fixed
  • βœ… AIOHA integrated smartly
  • βœ… Routing UX improved
  • βœ… Codebase looks cleaner

Thanks for following along! See you in the next post πŸš€


Happy Building! πŸ’»β€οΈ


πŸ“ Final Note


πŸš€ My Contributions to ♦️ Hive Ecosystem

Contribution To Hive Ecosystem
Hive Witness Node Hive API Node (in progress) 3Speak Video Encoder Node Operator (highest number of nodes) 3Speak Mobile App Developer
3Speak Podcast App Developer 3Speak Shorts App Developer 3Speak Support & Maintenance Team Distriator Developer
CheckinWithXYZ Hive Inbox HiFind Hive Donate App
Contributed to HiveAuth Mobile App Ecency ↔ 3Speak Integration Ecency ↔ InLeo Integration Ecency ↔ Actifit Integration
Hive Stats App Vote for Witness App HiveFlutterKit New 3Speak App

πŸ™Œ Support Back

❀️ Appreciate my work? Consider supporting @threespeak & @sagarkothari88! ❀️

Vote For Witness
sagarkothari88 @sagarkothari88
threespeak @threespeak