Customize the dashboard / welcome page

On v4.21.0 the redirect seems to be working for /admin but not /admin/.

1 Like

There’s an (at the moment Chrome-only) API that can be used for redirecting from /admin:

  bootstrap(app: any) {
    const url = "/admin/content-manager";

    if ("navigation" in window) {
      // Redirect soft /admin navigations to `url`
      // Chrome-only
      window.navigation.addEventListener("navigate", (e) => {
        const { pathname } = new URL(e.destination.url);

        if (new RegExp("^/admin/?$").test(pathname)) {
          window.navigation.navigate(url);
        }
      });
    }

    // Redirect hard /admin navigations to `url`
    if (new RegExp("^/admin/?$").test(location.pathname)) {
      location.href = url;
    }
  },

Also, in case you’re using TypeScript:

npm install -D @types/dom-navigation

Thanks for the idea of using bootstrap @Apostata.

2 Likes

Thanks for pointing this out @theSdev! I updated the repo, Gist, and post on my site.

If I could figure out how to edit previous posts in this forum, I’d do the same there, but:

module.exports = (config, { strapi }) => {
  const redirects = ["/", "/index.html", "/admin", "/admin/"].map((path) => ({
    method: "GET",
    path,
    handler: (ctx) => ctx.redirect("/admin/plugins/[YOUR-PLUGIN-NAME]"),
    config: { auth: false },
  }));

  strapi.server.routes(redirects);
};

Not sure about 4.20.0 but I’m using 4.21.1 and even /admin/ is not redirecting unless I perform a hard refresh after login.

not able to logout by using this code :joy:

But when you click on the top left logo or name, you still get redirected to /admin/

I found that while in develop mode, or clicking the “my-logo” link in the top left of admin panel, a refresh is needed for the route to kick in.

I also found this affecting production builds since time of writing. Until there’s a way to customize admin components again, this does not seem possible.

Hopefully strapi@5 will provide a way to achieve global route overrides.

For now i have used js inside app.js to remove the default admin panel and add custom componnent based on pathname