Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation in the admin panel is broken if routes.admin is set to "/" #6482

Closed
r1tsuu opened this issue May 23, 2024 · 7 comments · Fixed by #7276
Closed

Navigation in the admin panel is broken if routes.admin is set to "/" #6482

r1tsuu opened this issue May 23, 2024 · 7 comments · Fixed by #7276

Comments

@r1tsuu
Copy link
Member

r1tsuu commented May 23, 2024

Link to reproduction

No response

Payload Version

3.0.0-beta.35

Node Version

20

Next.js Version

15rc

Describe the Bug

When setting routes.admin: "/" links in the admin panel don't have slash at the start, resolving into a string like "collections/admins" which is invalid and doesn't work, instead we need to apply slash like we expect "/collections/admins"

Also i would mention that if i change Payload joi Validation to accept admin.routes empty string value "" then it works like i expect with "/".

Reproduction Steps

  1. Either use rewrites or change the directory of Payload admin pages
  2. Set routes.admin to "/".
  3. See that it breaks the navigation

Adapters and Plugins

No response

@r1tsuu r1tsuu added the v3 label May 23, 2024
@r1tsuu r1tsuu changed the title Navigation in the admin panel breaks if routes.admin is set to "/" Navigation in the admin panel is broken if routes.admin is set to "/" May 23, 2024
@JarrodMFlesch
Copy link
Contributor

JarrodMFlesch commented May 24, 2024

Hey @r1tsuu I think we should discuss what we want to do here. We would likely need to touch every file that uses adminRoute or routes.admin, and then adjust them accordingly. There are some places that will break if the admin route is "/" or "", bc the links or routes generated using it will be incorrect, i.e. "/admin/[route]" will become "//[route]".

You could in the meantime, add a redirect in your next config like so:

export default withBundleAnalyzer(
  withPayload({
    async redirects() {
      return [
        {
          destination: '/admin',
          permanent: true,
          source: '/',
        },
      ]
    },
  }),
)

@r1tsuu
Copy link
Member Author

r1tsuu commented May 24, 2024

Hey @r1tsuu I think we should discuss what we want to do here. We would likely need to touch every file that uses adminRoute or routes.admin, and then adjust them accordingly. There are some places that will break if the admin route is "/" or "", bc the links or routes generated using it will be incorrect, i.e. "/admin/[route]" will become "//[route]".

You could in the meantime, add a redirect in your next config like so:

export default withBundleAnalyzer(
  withPayload({
    async redirects() {
      return [
        {
          destination: '/admin',
          permanent: true,
          source: '/',
        },
      ]
    },
  }),
)

The problem is that i don't want to do a redirect here, because what i want is to host the admin panel on a different domain from frontend which is on the same server too.
What i do is i'm using NextResponse.rewrite in the middleware.ts if req.host is for the admin. So my "real" route is still "/admin" and i didn't change any folder structure.
I sucessfully achieved this working with providing routes.admin: "" without any broken links.
I'm not sure if it sounds good but if we just map the "/" value to "" in our sanitize function or joi schema then it should be fine, no need to change something else!

@JarrodMFlesch
Copy link
Contributor

@r1tsuu I tried that earlier, remapping inside the sanitize function. But after logging into the admin panel I was facing an issue with a Link component somewhere, saying the href was undefined 🤔

@jacobsfletch
Copy link
Member

I've got a feature started for this on the feat/root-admin branch. I will pick back up on this work shortly.

@jacobsfletch jacobsfletch linked a pull request Jul 23, 2024 that will close this issue
3 tasks
@jacobsfletch
Copy link
Member

@r1tsuu this should go out in the next release

@r1tsuu
Copy link
Member Author

r1tsuu commented Jul 23, 2024

@r1tsuu this should go out in the next release

Cool, thank you

Copy link
Contributor

github-actions bot commented Sep 7, 2024

This issue has been automatically locked.
Please open a new issue if this issue persists with any additional detail.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants