Getting matched route in request object

I need to have matched route in request object.

Let’s assume I have a route like this;

Route.get('api/users/:id', 'UsersController.show')

In the Controller method, I need to have the structure of the url matched. For example;

async show ({ request }) {
    console.log(request.matchedRoute)
    // api/users/:id
}

What can I do that? Is there any way to get that data?

1 Like

I solved this problem. We can use following code;

    let clearUrl = request.url()
    for (const key in params) {
      clearUrl = clearUrl.replace(params[key], key)
    }
2 Likes