Integrating Marblecms into Mantlz

Posted onDaly JeanDaly Jean4 min read
Integrating Marblecms into Mantlz

Feedgot, Simplified

Stop guessing. Get actionable feedback understand what users need, iterate faster, and ship with confidence.

free to start, no cc required

Solving Complex Routing Issues in Hybrid Next.js Applications

A comprehensive guide to resolving routing conflicts between Next.js App Router and React Router in modern web applications

Building modern web applications often requires combining multiple technologies to achieve the best user experience. In our recent project, we encountered a fascinating challenge: integrating a blog system within an application that uses both Next.js App Router and React Router. What seemed like a straightforward implementation quickly revealed complex architectural incompatibilities that required creative problem-solving.

The Challenge We Faced

Our application architecture presented a unique scenario:

  • Next.js App Router handled the main application with server-side rendering

  • React Router managed the frontend SPA components

  • Blog functionality needed to work seamlessly across both systems

The integration wasn't as simple as we initially thought. What appeared to be a standard routing setup quickly became a lesson in architectural complexity.

Three Critical Issues That Emerged

1. The Routing Disconnect

Imagine clicking a blog link in your application, only to be greeted by a 404 error. That's exactly what our users experienced. Our blog routes were perfectly configured in Next.js App Router, but React Router had no idea they existed.

The Problem: Two routing systems operating in isolation, creating invisible walls between different parts of our application.

User Impact: Broken navigation and frustrated users encountering dead ends when trying to access blog content.

2. The Environment Variable Trap

Our blog needed to communicate with MarbleCMS API using sensitive credentials. However, these environment variables were locked away in server-side contexts, inaccessible to our client-side components.

The Problem: Security restrictions preventing client-side access to server-only environment variables.

User Impact: "Environment variables not set" errors appearing instead of blog content, making the feature completely unusable.

3. The Context Collision

Perhaps the most subtle yet critical issue: trying to use Next.js server components within React Router's client-side rendering environment. It's like trying to fit a square peg in a round hole.

The Problem: Fundamental incompatibility between server-side and client-side rendering contexts.

User Impact: Hydration errors, component failures, and an unstable user experience.

Our Strategic Solution

Rather than forcing one routing system to dominate, we embraced a hybrid architecture that plays to each system's strengths. Think of it as creating bridges between two islands instead of trying to merge them into one.

The Four-Pillar Approach

1. Secure Server-Side API Layer

We created dedicated API endpoints that act as secure intermediaries between our client-side components and external services.

What we built:

  • /api/blog - Handles blog post listings

  • /api/blog/[slug] - Manages individual post retrieval

Why this works:

  • Environment variables stay secure on the server

  • Clean separation between data fetching and presentation

  • Consistent error handling across the application

// Clean, secure API endpoint
export async function GET() {
  try {
    const posts = await getPosts();
    return NextResponse.json({ posts });
  } catch (error) {
    return NextResponse.json(
      { error: 'Failed to fetch posts' },
      { status: 500 }
    );
  }
}

2. Smart Client-Side Interface

We developed a clean abstraction layer that handles all API communication, making it easy for components to fetch blog data without worrying about the underlying complexity.

Key features:

  • Type-safe API calls with full TypeScript support

  • Automatic error handling and retry logic

  • Consistent response formatting

  • Reusable across different components

3. The Universal Blog Component

This was our masterstroke: a single React component that works seamlessly in both routing environments. It's like having a bilingual translator that can speak both Next.js and React Router fluently.

Smart features:

  • Automatically detects its routing context

  • Extracts parameters from both useParams and props

  • Handles loading states and errors gracefully

  • Optimized for both server-side and client-side rendering

The beauty of this approach: Write once, run everywhere. No more maintaining separate components for different routing systems.

4. Seamless Router Integration

The final piece was updating our React Router configuration to recognize blog routes, creating a unified navigation experience.

Simple addition:

Big impact:

  • Instant navigation between blog posts

  • Lazy loading for optimal performance

  • Consistent user experience across the entire application

Before and After: A Tale of Two Architectures

The Broken Architecture ❌

React Router → Next.js Server Components → MarbleCMS API
           (Conflict Zone - Nothing Works)

Problems:

  • Routing systems fighting each other

  • Environment variables trapped on the server

  • Components crashing in wrong contexts

The Elegant Solution ✅

# Blog Listing (/blog)
Next.js App Router → Server Components → MarbleCMS API
                  (Perfect for SEO & Performance)

# Individual Posts (/blog/[slug])
React Router → Client Components → API Routes → MarbleCMS API
            (Smooth Navigation)  (Secure Bridge)

Benefits:

  • Each system does what it does best

  • Security maintained through proper separation

  • Performance optimized for each use case

  • Users get a seamless experience

The Results: A Success Story

What We Achieved ✅

Perfect Functionality:

  • Blog listing page loads instantly with server-side rendering

  • Individual blog posts accessible from anywhere in the application

  • Smooth navigation between posts without page refreshes

  • Robust error handling that gracefully manages edge cases

  • Mobile-responsive design that works across all devices

Technical Excellence:

  • Secure API communication with proper authentication

  • SEO-optimized content for better search visibility

  • Performance-optimized loading with smart caching

  • Type-safe code with full TypeScript integration

The Implementation Breakdown

New Files Created:

  • API endpoints for secure data fetching

  • Client-side interface for clean API communication

  • Universal blog component that works everywhere

Existing Files Enhanced:

  • Router configuration updated for seamless navigation

  • Blog pages refactored for better performance

Collect and prioritize feedback. Ship what customers want

Centralize customer input in boards, prioritize with votes, keep roadmaps in sync, and publish changelogs automatically. Built for SaaS teams.