Route Resolver for Inverse Relationship

Is it possible to create a route resolver that utilizes an inverse relationship to get the parent of the current item? In other words:

I have a collection of courses, and each course uses content relationships to get the lessons for the course:

course
- lesson1
- lesson2

However, the URLs for the lessons should include the uid of the course, such as site.com/course-uid/lesson1. Is it possible to achieve this utilizing a route resolver? My lessons don't relate to the courses themselves, only through the relationship of the course documents.

Thanks!

Hello @jwinton

Thanks for reaching out to us.

You haven't mentioned the framework so I describe my answer based on Nuxt.js. You can Create folder structure in your project as /course/_uid/_uid. Whenever you want to know the uid value, try to access all params.
For example:

  1. At /course/_uid/ ,there will be only one params value that will be only uid value, which is course-uid.
  2. At /course/_uid/_uid ,there will be only one params value. It will be 2 uid values, which are course-uid and lesson_uid.

Give this atry and let me know if you have any further questions.

Thanks,
Priyanka

Thank you! I should have mentioned that the application is in Next.js; do you have an example of how to create a route resolver function? I've currently got a linkResolver set up, but it requires passing the courseUid from the query params down manually, and it would be a lot simpler for it to be automatic.

Thanks!

Hello @jwinton,

In the case of Next.js, you can use slugs to check whether the URL is /course-id or /course/lesson-id.

  1. create a dynamic route as /..slug.js and get all the params from URL using router.query.
  2. Create 2 separate functions for course and lesson content operations.
  3. If router.query is returning 1 params, i.e. it is course level and the function of redirection of course should be executed.
  4. If router.query is returning 2 params, i.e. it is course level and the function of redirection of lesson should be executed.

I hope it answers your question. Let me know if you have any further questions.

Thanks,
Piyanka