Hi,
I found this video : Replace findOne per ID by slug | Strapi on strapi video library. It is cool nad it is just what I need and only problem that I have with it is that it refers to older version (I’m using v4.0.5).
Step with controller is pretty much the same. I’ve took controller/article.js and wrote something like this (I should say I’ve compie/paste it from documentation):
const { createCoreController } = require("@strapi/strapi").factories;
module.exports = createCoreController("api::article.article", ({ strapi }) => ({
async findOne(ctx) {
const { slug } = ctx.params;
const { query } = ctx;
const entity = await strapi
.service("api::article.restaurant")
.findOne(slug, query);
const sanitizedEntity = await this.sanitizeOutput(entity, ctx);
return this.transformResponse(sanitizedEntity);
},
}));
Second step is to override rout to get not id, but slug. However I can’t find config/routes.json file. Instead there is routes/article.js and it looks like I should change something there. I find this article /developer-docs/latest/development/backend-customization/routes.html in documentation but it didn’t help me much.
So I’m looking for help with this.
P.S. Last link is not user friendly becaus new users can add only two links in one post and I’m a new user