Edit root page strapi

I found a solution. Recently i’ve installed strapi 4.16.2 for my client. My client want to see login page as root url. To do this i created a global middleware using strapi cli
Type npm run strapi generate in terminal then select middleware and give middleware name.
then select first option Add middleware to root of project
your global middleware is created in src/middlewares/your_middleware.ts
Now replace code below

import { Strapi } from “@strapi/strapi”;
export default (config, { strapi }: { strapi: Strapi }) => {

return async (ctx, next) => {
// use ctx.request to get request method and request path
if (ctx.request.method === “GET” && ctx.request.path === “/”) {
// use ctx.response.redirect(url,alt) to redirect root url to your admin url
ctx.response.redirect(“/your_desire_url”, “/admin”);
}
await next();
};
};

To activate your middleware open config/middlewares.ts and add this line
global::your_middleware_name,

Now run strapi app and see the result.

1 Like