2

Nuxt JS creates its routes based on the file system. You typically require templates to be set up for the dynamic params, like _id.vue etc.

However, my backend developer has a CMS that spits out JSON with links to pages that sit on entirely dynamic URL's.

e.g. /about-us/people/michael/

There's no way for me to know ahead of time how these kinds of URL's should be routed with Nuxt's file-based system.

Some links could look like: /articles/hello-world/ etc.

Is there any info on how I can capture all routes, no matter how far the nesting goes?

I'm able to do the first level by having index.vue and _slug.vue, (e.g. /about-us/). Beyond that, it's a mystery how I'd solve having /about-us/people/ etc without it throwing a 404.

Help much appreciated.

1 Answer 1

3

You could use extendRoutes

module.exports = {
  router: {
    extendRoutes (routes, resolve) {
      routes.push({
        name: 'catchall',
        path: '*',
        component: resolve(__dirname, 'pages/catchallpage.vue')
      })
    }
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, this is the route I end up going down. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.