Home > front end >  Create a catchall dynamic route in remix
Create a catchall dynamic route in remix

Time:01-19

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.

CodePudding user response:

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

  • Related