The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
Rocket.Chat/client/lib/createRouteGroup.ts

40 lines
1.1 KiB

import { FlowRouter } from 'meteor/kadira:flow-router';
import type { ElementType } from 'react';
import { renderRouteComponent } from '../reactAdapters';
type RouteRegister = {
(path: string, params: {
name: string;
lazyRouteComponent: () => Promise<ElementType>;
props: Record<string, unknown>;
action: (params?: Record<string, string>, queryParams?: Record<string, string>) => void;
}): void;
};
export const createRouteGroup = (name: string, prefix: string, importRouter: () => Promise<ElementType>): RouteRegister => {
const routeGroup = FlowRouter.group({
name,
prefix,
});
const registerRoute: RouteRegister = (path, { lazyRouteComponent, props, action, ...options }) => {
routeGroup.route(path, {
...options,
action: (params, queryParams) => {
if (action) {
action(params, queryParams);
return;
}
renderRouteComponent(importRouter, {
template: 'main',
region: 'center',
propsFn: () => ({ lazyRouteComponent, ...options, params, queryParams, ...props }),
});
},
});
};
return registerRoute;
};