Use Markdown Files in the Next.js Pages Directory Instead of React Components

John Lindquist
InstructorJohn Lindquist

Share this video with your friends

Send Tweet
Published 3 years ago
Updated 3 years ago

With a couple of tweaks to the next.config.js, you can begin using Markdown files which will be represented by URLs in the pages directory. With this approach, you could author an entire site using only Markdown files and sprinkling in React components inside your Markdown files where necessary.

Instructor: [0:00] With a content markdown file inside of our pages directory, you might assume you could navigate to content and see that page, but we get a 404. You can enable this by going into your config, and inside of with MDX, pass in an object for your configuration with a page extensions property.

[0:20] This is an array. We need to pass in JavaScript so that our default JS file is supported, so JS. We'll just add MDX as well. I'll hit save.

[0:35] Next, we'll pickup that change automatically and even refresh page this page for you, and you can see it's now rendering this content page at the /content URL. If I create another page, we'll call it new file about .MDX with header one, just [inaudible] about, hit save and navigate to about.