blog

Tab Navigation vs Route-Based Navigation in React: My Experience with Large Datasets - Blog - Naufaldi Rafif Satriya

Today I want to share my journey with a common React challenge: choosing between tab navigation and route-based navigation for dashboards with large datas...

Tab Navigation vs Route-Based Navigation in React: My Experience with Large Datasets - Blog - Naufaldi Rafif Satriya

Today I want to share my journey with a common React challenge: choosing between tab navigation and route-based navigation for dashboards with large datasets.

The Problem I Faced

Last month, I was working on a dashboard project that displayed around 1000 user records across multiple views. I needed to decide: should I use tabs within a single page or create separate routes for each view?

It wasn't an easy decision. I had to think about:

  • Performance with large datasets
  • User experience and navigation flow
  • Memory management
  • Code organization

What The Documentation Says

According to React Router documentation, route-based navigation is recommended for complex applications with distinct views, while component-based tab navigation works well for related content that needs to maintain shared state.

The React community generally agrees that route-based navigation provides better code organization and supports the web's natural linking and history capabilities. However, this is just general guidance - we need real metrics for our specific use case.

My Experience with Both Approaches

Tab Navigation: The Good and Bad

function Dashboard() {
  const [activeTab, setActiveTab] = useState(0);
  
  return (
    <div>
      <div className="tabs">
        <button onClick={() => setActiveTab(0)}>Products</button>
        <button onClick={() => setActiveTab(1)}>Users</button>
        <button onClick={() => setActiveTab(2)}>Orders</button>
      </div>
      
      {activeTab === 0 && <ProductsPanel />}
      {activeTab === 1 && <UsersPanel />}
      {activeTab === 2 && <OrdersPanel />}
    </div>
  );
}

Strengths:

  • Fast switching between views (felt instant to users)
  • Preserved state between tab switches
  • Simpler implementation initially
  • No need to handle route management

Weaknesses:

  • Memory usage increased dramatically with dataset size
  • Initial load time was longer since all tabs needed to initialize
  • Testing became more complicated
  • No direct URLs for specific views

Route-Based Navigation: The Trade-offs

function App() {
  return (
    <BrowserRouter>
      <Routes>
        <Route path="/" element={<Dashboard />}>
          <Route index element={<Navigate to="products" />} />
          <Route path="products" element={<ProductsView />} />
          <Route path="users" element={<UsersView />} />
          <Route path="orders" element={<OrdersView />} />
        </Route>
      </Routes>
    </BrowserRouter>
  );
}

Strengths:

  • Better memory management
  • Cleaner architecture and separation of concerns
  • Support for direct links to specific views
  • Better code splitting possibilities

Weaknesses:

  • Slightly slower navigation experience
  • Extra work to maintain state between route changes
  • More complex implementation initially

Measuring Real Performance

To make a data-driven decision, I measured both approaches using Chrome DevTools with a dataset of 1000 records:

Metric

Tab-Based

Route-Based

Memory Usage

~130MB

~65MB

Initial Load

~2.8s

~1.6s

Navigation Time

~80ms

~350ms

DOM Elements

~3200

~1200

The tab navigation approach used nearly twice as much memory and had significantly more DOM elements, which explained the occasional freezing issues.

Making Route-Based Navigation Better

To address the slower navigation of route-based approach, I implemented:

  • Optimistic UI updates - Show the new view immediately while data loads
  • Data caching with React Query - Store previously fetched data
function UsersView() {
  const [page, setPage] = useState(1);
  
  const { data, isLoading } = useQuery(
    ['users', page],
    () => fetchUsers(page),
    { 
      keepPreviousData: true,
      staleTime: 5 * 60 * 1000 // 5 minutes
    }
  );
  
  if (isLoading && !data) return <LoadingSpinner />;
  
  return (
    <div>
      {/* User data display */}
      <Pagination currentPage={page} onChange={setPage} />
    </div>
  );
}

With these optimizations, the navigation delay became barely noticeable but we kept the memory benefits.

What I Learned

From my perspective, here's what I recommend:

Use tab navigation when:

  • Your dataset is small (under 200 records)
  • Users need to frequently compare data between tabs
  • Immediate switching is critical to your UX

Use route-based navigation when:

  • You're dealing with large datasets (500+ records)
  • Memory issues are appearing in your app
  • You need bookmarkable URLs
  • Your app architecture needs to scale

Remember, these recommendations come from my specific experience - your mileage may vary depending on your exact requirements and constraints!

What navigation approach has worked best for your projects? I'd love to hear your experiences in the comments!

Bagikan[](https://twitter.com/share?text=Tab Navigation vs Route-Based Navigation in React: My Experience with Large Datasets&url=https://blog.naufaldi.com/tab-navigation-vs-route-based-navigation-in-react-my-experience-with-large-datasets/ "Twitter")[](https://www.facebook.com/sharer/sharer.php?u=https://blog.naufaldi.com/tab-navigation-vs-route-based-navigation-in-react-my-experience-with-large-datasets/ "Facebook")[](https://www.linkedin.com/shareArticle?mini=true&url=https://blog.naufaldi.com/tab-navigation-vs-route-based-navigation-in-react-my-experience-with-large-datasets//&title=Tab Navigation vs Route-Based Navigation in React: My Experience with Large Datasets "LinkedIn")[](/cdn-cgi/l/email-protection#625d111700080701165f360300422c03140b0503160b0d0c42141142300d1716074f2003110706422c03140b0503160b0d0c420b0c42300703011658422f1b42271a1207100b070c010742150b160a422e0310050742260316031107161144030f1259000d061b5f0a161612584d4d000e0d054c04030e060b4c1a1b184d1603004f0c03140b0503160b0d0c4f14114f100d1716074f00031107064f0c03140b0503160b0d0c4f0b0c4f10070301164f0f1b4f071a1207100b070c01074f150b160a4f0e031005074f06031603110716114d "Email")

Topik Insight Lesson Learned Tutorial

[

Catching Up with AI

Ever felt stuck in a project without clear direction? Working alone without…

19 Apr 2025

](/catching-up-with-ai/)[

Open Journal : A Day of Reflection and Action

Recap Yesterday Yesterday, I spent most of the day working from the…

21 Feb 2025

](/open-journal-a-day-of-reflection-and-action/)