chore: getHref

This commit is contained in:
chenos 2025-01-08 21:32:31 +08:00
parent 1d2b237e73
commit 3c83c1b9cd
3 changed files with 11 additions and 11 deletions

View File

@ -208,7 +208,7 @@ export class Application {
return this.getPublicPath() + pathname.replace(/^\//g, ''); return this.getPublicPath() + pathname.replace(/^\//g, '');
} }
getFullUrl(pathname: string) { getHref(pathname: string) {
const name = this.name; const name = this.name;
if (name && name !== 'main') { if (name && name !== 'main') {
return this.getPublicPath() + 'apps/' + name + '/' + pathname.replace(/^\//g, ''); return this.getPublicPath() + 'apps/' + name + '/' + pathname.replace(/^\//g, '');

View File

@ -85,29 +85,29 @@ describe('Application', () => {
}); });
}); });
describe('getFullUrl', () => { describe('getHref', () => {
it('default', () => { it('default', () => {
const app = new Application({}); const app = new Application({});
expect(app.getFullUrl('test')).toBe('/test'); expect(app.getHref('test')).toBe('/test');
expect(app.getFullUrl('/test')).toBe('/test'); expect(app.getHref('/test')).toBe('/test');
}); });
it('custom', () => { it('custom', () => {
const app = new Application({ publicPath: '/nocobase' }); const app = new Application({ publicPath: '/nocobase' });
expect(app.getFullUrl('/test')).toBe('/nocobase/test'); expect(app.getHref('/test')).toBe('/nocobase/test');
expect(app.getFullUrl('test')).toBe('/nocobase/test'); expect(app.getHref('test')).toBe('/nocobase/test');
}); });
it('sub app', () => { it('sub app', () => {
const app = new Application({ name: 'sub1' }); const app = new Application({ name: 'sub1' });
expect(app.getFullUrl('test')).toBe('/apps/sub1/test'); expect(app.getHref('test')).toBe('/apps/sub1/test');
expect(app.getFullUrl('/test')).toBe('/apps/sub1/test'); expect(app.getHref('/test')).toBe('/apps/sub1/test');
}); });
it('sub app', () => { it('sub app', () => {
const app = new Application({ name: 'sub1', publicPath: '/nocobase/' }); const app = new Application({ name: 'sub1', publicPath: '/nocobase/' });
expect(app.getFullUrl('test')).toBe('/nocobase/apps/sub1/test'); expect(app.getHref('test')).toBe('/nocobase/apps/sub1/test');
expect(app.getFullUrl('/test')).toBe('/nocobase/apps/sub1/test'); expect(app.getHref('/test')).toBe('/nocobase/apps/sub1/test');
}); });
}); });

View File

@ -95,7 +95,7 @@ export const DesktopModeHeader: FC = () => {
} }
`} `}
> >
<Button style={{ color: 'white' }} href={app.getFullUrl('/admin')}> <Button style={{ color: 'white' }} href={app.getHref('/admin')}>
{t('Back')} {t('Back')}
</Button> </Button>
<div style={{ display: 'flex', alignItems: 'center' }}> <div style={{ display: 'flex', alignItems: 'center' }}>