<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Miguel Quintal</title>
    <description>The latest articles on DEV Community by Miguel Quintal (@mquintal).</description>
    <link>https://dev.to/mquintal</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3266792%2Fda474671-653d-41d1-87cb-b18a2127f90b.png</url>
      <title>DEV Community: Miguel Quintal</title>
      <link>https://dev.to/mquintal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mquintal"/>
    <language>en</language>
    <item>
      <title>How to built a static site React Router v7 + MDX</title>
      <dc:creator>Miguel Quintal</dc:creator>
      <pubDate>Fri, 20 Jun 2025 20:09:57 +0000</pubDate>
      <link>https://dev.to/mquintal/how-to-built-a-static-site-react-router-v7-mdx-4lc1</link>
      <guid>https://dev.to/mquintal/how-to-built-a-static-site-react-router-v7-mdx-4lc1</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Tired of overcomplicated static site generators? Want to build your docs, blog, or site using just &lt;a href="https://reactrouter.com/start/framework/installation#installation" rel="noopener noreferrer"&gt;React Router v7&lt;/a&gt; + MDX? Meet &lt;a href="https://github.com/mquintal/react-router-mdx" rel="noopener noreferrer"&gt;react-router-mdx&lt;/a&gt; — a small but powerful tool to generate static web sites. Check out our &lt;a href="https://react-router-mdx.netlify.app/" rel="noopener noreferrer"&gt;demo page&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🧠 Why react-router-mdx?
&lt;/h2&gt;

&lt;p&gt;Well, it keeps the process of creating static web pages based on MDX simple. No need for &lt;a href="https://vite.dev/" rel="noopener noreferrer"&gt;vite&lt;/a&gt; plugins and other dependencies. You just need to install it, setup where your MDX files are and viola!&lt;/p&gt;

&lt;p&gt;That is where &lt;code&gt;react-router-mdx&lt;/code&gt; comes in:&lt;/p&gt;

&lt;p&gt;🔥 Automatic MDX route generation from a folder and file naming&lt;/p&gt;

&lt;p&gt;🧩 Fully compatible with React Router v7 (Framework mode)&lt;/p&gt;

&lt;p&gt;🛠️ Minimal setup — no custom compiler or extra dependencies&lt;/p&gt;

&lt;p&gt;📦 SSR/Pre-rendering using react-router build&lt;/p&gt;




&lt;h2&gt;
  
  
  🚀 Installation
&lt;/h2&gt;

&lt;p&gt;Make sure you're using &lt;a href="https://reactrouter.com/start/framework/installation#installation" rel="noopener noreferrer"&gt;React Router v7 (Framework mode)&lt;/a&gt;. Once you have generated the React Router project your project's folder structure should look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my-amazing-webpage/
├── public/
├── app/
│   ├── home/
│   ├── routes/
│   │   └── home.tsx
│   ├── root.tsx
│   ├── routes.tsx
│   └── app.css
├── .gitignore
├── package.json
├── react-router.config.ts
├── tsconfig.json
└── vite.config.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using &lt;code&gt;yarn&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn add react-router-mdx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using &lt;code&gt;npm&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;react-router-mdx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🛠️ Set it up
&lt;/h2&gt;

&lt;p&gt;1- Change your &lt;code&gt;react-router.config.ts&lt;/code&gt; to init the and provide the pre-rendered paths.&lt;/p&gt;

&lt;p&gt;Your &lt;code&gt;react-router.config.ts&lt;/code&gt; should look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Config&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@react-router/dev/config&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;init&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-router-mdx/server&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mdx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;posts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;ssr&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;prerender&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;mdx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;paths&lt;/span&gt;&lt;span class="p"&gt;())];&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;satisfies&lt;/span&gt; &lt;span class="nx"&gt;Config&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;path&lt;/code&gt; passed to the &lt;code&gt;init&lt;/code&gt; should the folder where you'll keep your MDX files.&lt;/p&gt;

&lt;p&gt;2- Create &lt;code&gt;hello-world.mdx&lt;/code&gt; file under &lt;code&gt;posts&lt;/code&gt; directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;posts/
└─ hello-world.mdx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;posts/hello-world.mdx&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;---
title: hello world title
---
# hello world

This is a hello World mdx file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3- Add MDX routes to your &lt;code&gt;app/routes.ts&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { index } from "@react-router/dev/routes";
import { routes } from 'react-router-mdx/server'

export default [
    index("routes/home.tsx"),
    ...routes("./routes/post.tsx")
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4- Add MDX routes to your &lt;code&gt;app/routes/posts.ts&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { loadMdx } from 'react-router-mdx/server'
import { useMdxComponent } from "react-router-mdx/client"
import type { Route } from "./+types/post";

export const loader = async ({ request }: Route.LoaderArgs) =&amp;gt; {
  return loadMdx(request)
}

export default function Home() {
  const Component = useMdxComponent()
  return (
    &amp;lt;Component /&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now if you run &lt;code&gt;yarn dev&lt;/code&gt; you should have the page based on &lt;code&gt;posts/hello-world.mdx&lt;/code&gt; on &lt;a href="http://localhost:5173/posts/hello-world" rel="noopener noreferrer"&gt;http://localhost:/posts/hello-world&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🙌 Conclusion
&lt;/h2&gt;

&lt;p&gt;If you're building a React Router v7-based site and want Markdown + React support with minimal friction, give &lt;code&gt;react-router-mdx&lt;/code&gt; a shot. It's ideal for:&lt;/p&gt;

&lt;p&gt;📚 Documentation sites&lt;/p&gt;

&lt;p&gt;📝 Personal blogs&lt;/p&gt;

&lt;p&gt;🧪 Component previews / style guides&lt;/p&gt;

&lt;p&gt;Let me know what you build with it — contributions and feedback welcome!&lt;/p&gt;

</description>
      <category>react</category>
      <category>reactrouter</category>
      <category>mdx</category>
    </item>
  </channel>
</rss>
