2022-03-17 09:41:48 +08:00
|
|
|
import { Spin } from 'antd';
|
2022-01-10 19:22:21 +08:00
|
|
|
import React from 'react';
|
2022-03-17 09:41:48 +08:00
|
|
|
import { useRequest } from '../api-client';
|
2022-01-10 19:22:21 +08:00
|
|
|
import { RouteSwitchContext } from './context';
|
|
|
|
import { RouteSwitchProviderProps } from './types';
|
|
|
|
|
|
|
|
export function RouteSwitchProvider(props: RouteSwitchProviderProps) {
|
2022-03-17 09:41:48 +08:00
|
|
|
const { children, components, routes } = props;
|
|
|
|
return <RouteSwitchContext.Provider value={{ routes, components }}>{children}</RouteSwitchContext.Provider>;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function RemoteRouteSwitchProvider(props: RouteSwitchProviderProps) {
|
|
|
|
const { data, loading } = useRequest({
|
|
|
|
url: 'uiRoutes:getAccessible',
|
|
|
|
});
|
|
|
|
if (loading) {
|
|
|
|
return <Spin />;
|
|
|
|
}
|
|
|
|
return <RouteSwitchProvider {...props} routes={data?.data || []} />;
|
2022-01-10 19:22:21 +08:00
|
|
|
}
|