1. 9
    Create a Dynamic Segment in Remix
    3m

Create a Dynamic Segment in Remix

InstructorKent C. Dodds

Share this video with your friends

Send Tweet

It’s not feasible to create a new route file for every single blog post we want to publish! Instead we can use the $slug.tsx filename convention with the dollar sign prefix to create a dynamic segment. Whatever you name the file is what the param will be called in your component.

Then there are a couple steps to take to get posts from your db based on the url param. First you’ll write a getPost method in your post.server.ts file that finds a unique post based on the slug. Then write a loader function that calls your getPost method and returns JSON with your post.

Victor
~ a year ago

This is now outdated, you're much better just following this tutorial on remix.run, https://remix.run/docs/en/main/tutorials/blog