The order of routes does not work in the Route.group() method.
_ProductController.js_
``` js ProductController
async category({ response }) {
console.log('category');
}
async show({ response }) {
console.log('show');
}
**case 1**
_routes.js_
``` js routes.js
Route.group(() => {
Route.get('/product/category', 'ProductController.category');
Route.get('/product/:id', 'ProductController.show');
})
.prefix('api');
You can see 'show' in console.
case 2
_routes.js_
``` js routes.js
Route.get('/product/category', 'ProductController.category');
Route.group(() => {
Route.get('/product/:id', 'ProductController.show');
})
.prefix('api');
```
Now 'category', 'show' in console.
I wonder if the order in Route.group() method is irrelevant to the route, or is it a bug?
Can you share the URL you hit from the browser?

Using your routes, this is output I get, which is the same order as routes get matched, which seems fine to me
// ProductController.js
async categories() {
console.log('categories')
}
async detail() {
console.log('show')
}
case 1
// routes.js
Route.group(() => {
Route.get('/product/category/:id?', 'ProductController.categories');
Route.get('/product/:id', 'ProductController.detail');
})
.prefix('api/v1')
.formats(['json']);
case 2
// routes.js
Route.get('/api/v1/product/category/:id?', 'ProductController.categories');
Route.group(() => {
Route.get('/product/:id', 'ProductController.detail');
})
.prefix('api/v1')
.formats(['json']);
API calls in postman
case 1

GET /api/v1/product/category
case 2

GET /api/v1/product/category

As per your routes definition in case1 you have registered 2 routes, but screenshot of case1 shows 3 on the terminal.
Can u create a sample app which reproduces the issue
sample app
case 1

case 2

I mean share the repo of this app, screenshots are not something I can use to debug
@thetutlage
馃憤
https://github.com/brendaniel/adonis-route-test/
Looks to me the root of the issue is actually .formats() and the normally optional trailing slash.
If you request /api/product/category/ or /api/product/category/.json it does resolve categories while without the slash it resolves show. Same thing with case2 if you add .formats(['json']) to the outside route it will behave the same.
Going to look into it in a while
Created an issue on the internal library Adonis uses, let's see what best can be done here https://github.com/pillarjs/path-to-regexp/issues/131
I am afraid, I don't think I can fix it anyway unless the internal library path-to-regexp fixes it. The only option is to re-write the functionality of path-to-regexp, which I have no plans to do it right now.
@thetutlage appreciate your time
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.