Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Create a catchall dynamic route in remix

I’m using remix to serve my react application.
All my pages have dynamic slugs, therefore I need to find a way to resolve the following type of URL:
eg. mywebsite.com/dynamic_slug

If I create an $index.jsx file in the routes folder it works in that all the dynamic URLs resolve to that file, BUT, I can’t seem to find a way to then read the slug in the compontent so that I serve the right data.

Many thanks to any responders.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You access the dynamic params via the params object passed to your loaders and actions.

// routes/$index.jsx

export async function loader({request, params, context}) {
  const slug = params.index // whatever $name is
  //...
}

https://remix.run/docs/en/v1/guides/data-loading#route-params

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading