Config.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import Collection from '../pages/collections/Collection';
  2. import Collections from '../pages/collections/Collections';
  3. import Connect from '../pages/connect/Connect';
  4. import Overview from '../pages/overview/Overview';
  5. // import VectorSearch from '../pages/seach/VectorSearch';
  6. import { RouterConfigType } from './Types';
  7. import loadable from '@loadable/component';
  8. import Users from '../pages/user/User';
  9. const RouterConfig: RouterConfigType[] = [
  10. {
  11. path: '/',
  12. component: Overview,
  13. auth: true,
  14. },
  15. {
  16. path: '/connect',
  17. component: Connect,
  18. auth: false,
  19. },
  20. {
  21. path: '/collections',
  22. component: Collections,
  23. auth: true,
  24. },
  25. {
  26. path: '/collections/:collectionName',
  27. component: Collection,
  28. auth: true,
  29. },
  30. { path: '/users', component: Users, auth: true },
  31. ];
  32. async function importAll(r: any) {
  33. Object.keys(r).forEach((key: any) => {
  34. const content = r[key];
  35. const dirName = key.split('/config.json').shift().split('/')[1];
  36. const pathName = content.client?.path;
  37. const fileEntry = content.client?.entry;
  38. if (!pathName || !fileEntry) return;
  39. const auth = content.client?.auth || false;
  40. const OtherComponent = loadable(
  41. () => import(`../${dirName}/${pathName}/${fileEntry}.tsx`)
  42. );
  43. RouterConfig.push({
  44. path: `/${pathName}`,
  45. component: OtherComponent,
  46. auth,
  47. });
  48. });
  49. }
  50. const pluginConfigs = import.meta.glob(`../plugins/**/config.json`, {
  51. eager: true,
  52. });
  53. importAll(pluginConfigs);
  54. export default RouterConfig;