Files
payload/packages/ui/src/utilities/formatAdminURL.ts
Patrik 3d89508ce3 fix(ui): reincorporate basePath into logout component link (#7451)
## Description

Fixes issue where the `basePath` from the `next-config` was not
respected for the `logout` button link

- [x] I have read and understand the
[CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md)
document in this repository.

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)

## Checklist:

- [x] Existing test suite passes locally with my changes
2024-07-31 11:00:02 -04:00

24 lines
628 B
TypeScript

import type { Config } from 'payload'
/** Will read the `routes.admin` config and appropriately handle `"/"` admin paths */
export const formatAdminURL = (args: {
adminRoute: Config['routes']['admin']
basePath?: string
path: string
serverURL?: Config['serverURL']
}): string => {
const { adminRoute, basePath = '', path, serverURL } = args
if (adminRoute) {
if (adminRoute === '/') {
if (!path) {
return `${serverURL || ''}${basePath}${adminRoute}`
}
} else {
return `${serverURL || ''}${basePath}${adminRoute}${path}`
}
}
return `${serverURL || ''}${basePath}${path}`
}