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

John Lindquist
InstructorJohn Lindquist
Share this video with your friends

Social Share Links

Send Tweet
Published 6 years ago
Updated 5 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.

egghead
egghead
~ an hour ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today