Hi, In Strapi 3 all routes were handled in the routes.json. When a new content type was added, all core routes were added to this routes.json automatically. When there was a need for an additional route, I could duplicate on of the existing routes and modify it.
Now with Strapi 4 the routes are not added to a routes file anymore, instead only a createCoreRouter() function is called which dynamically creates all core routes.
For modifying the routes, the Strapi 4 Documentation lists two ways:
First, modifying the core routes by adding a second paramater to this createCoreRouter() function.
Second, using a custom router and adding all routes manually.
However, I would like to use a combination of both. I want to use all core routes but additionally some custom ones e.g. “deleteAllExpired”.
Is there a way to create a custom additional route, without rebuilting the core routes manually? e.g. extending the createCoreRouter() function with some custom routes? I did not find an example on how to do this.
This works where the path does not include the content-type, which is not really combining the routes as the OP specifies but creating a separate route, is there a way to combine/extend routes like in v3?
E.g. path: "/the-content-types/my-custom-route" won’t work resulting in a 404 I guess because of the way createCoreRouter creates defined routes whereas path: "/foo/my-custom-route" or path: "/my-custom-route" will resolve. A feature where createCoreRouter could be passed additional routes could be nice
Very useful, thanks! Just a follow-up question, how will I do the exact same thing but with the user api? That is, I want to add some extra routes to the user api. But I can’t seem to apply your answer because there’s no user folder under api, so there’s also no routes > user.js file where I could put your code snippet.