Files
directus/src/modules/register.ts
Rijk van Zanten e2664ad3fb Module based routing (#104)
* Initial commit

* Export registerModule function

* Add unit tests for module registration
2020-02-18 15:47:58 -05:00

27 lines
848 B
TypeScript

import router from '@/router';
import { ModuleConfig } from '@/modules/types';
import CollectionsModule from './collections/';
import FilesModule from './files/';
import SettingsModule from './settings/';
import UsersModule from './users/';
// The core modules are available regardless of project, so they can be registered immediately
[CollectionsModule, FilesModule, SettingsModule, UsersModule].forEach(registerModule);
export function registerModule(config: ModuleConfig) {
const routes = config.routes.map(route => ({
...route,
path: `/:project/${config.id}${route.path}`
}));
router.addRoutes(routes);
}
/**
* @NOTE
* The system modules that are registered here will most likely have to be re-registered on login
* as reset the router on logout to prevent custom modules from persisting between project switches
* wrongly
*/