mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-27 02:42:25 +08:00
feat(infra): route package (#10353)
This commit is contained in:
13
packages/frontend/routes/src/__tests__/routes.spec.ts
Normal file
13
packages/frontend/routes/src/__tests__/routes.spec.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { FACTORIES } from '../routes';
|
||||
|
||||
describe('PATH_FACTORIES', () => {
|
||||
it('should generate correct paths', () => {
|
||||
expect(
|
||||
FACTORIES.admin.settings.module({
|
||||
module: 'auth',
|
||||
})
|
||||
).toBe('/admin/settings/auth');
|
||||
});
|
||||
});
|
||||
44
packages/frontend/routes/src/routes.ts
Normal file
44
packages/frontend/routes/src/routes.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
// #region Path Parameter Types
|
||||
export interface RouteParamsTypes {
|
||||
admin: { settings: { module: { module: string } } };
|
||||
}
|
||||
// #endregion
|
||||
|
||||
// #region Absolute Paths
|
||||
export const ROUTES = {
|
||||
index: '/',
|
||||
admin: {
|
||||
index: '/admin',
|
||||
accounts: '/admin/accounts',
|
||||
ai: '/admin/ai',
|
||||
settings: { index: '/admin/settings', module: '/admin/settings/:module' },
|
||||
about: '/admin/about',
|
||||
},
|
||||
};
|
||||
// #endregion
|
||||
|
||||
// #region Relative Paths
|
||||
export const RELATIVE_ROUTES = {
|
||||
index: '/',
|
||||
admin: {
|
||||
index: 'admin',
|
||||
accounts: 'accounts',
|
||||
ai: 'ai',
|
||||
settings: { index: 'settings', module: ':module' },
|
||||
about: 'about',
|
||||
},
|
||||
};
|
||||
// #endregion
|
||||
|
||||
// #region Path Factories
|
||||
const home = () => '/';
|
||||
const admin = () => '/admin';
|
||||
admin.accounts = () => '/admin/accounts';
|
||||
admin.ai = () => '/admin/ai';
|
||||
const admin_settings = () => '/admin/settings';
|
||||
admin_settings.module = (params: { module: string }) =>
|
||||
`/admin/settings/${params.module}`;
|
||||
admin.settings = admin_settings;
|
||||
admin.about = () => '/admin/about';
|
||||
export const FACTORIES = { admin, home };
|
||||
// #endregion
|
||||
Reference in New Issue
Block a user