Из документов: https://reactrouter.com/6.30.1/route/route
Type declaration
interface RouteObject {
path?: string;
index?: boolean;
children?: RouteObject[];
caseSensitive?: boolean;
id?: string;
loader?: LoaderFunction;
action?: ActionFunction;
element?: React.ReactNode | null;
hydrateFallbackElement?: React.ReactNode | null;
errorElement?: React.ReactNode | null;
Component?: React.ComponentType | null;
HydrateFallback?: React.ComponentType | null;
ErrorBoundary?: React.ComponentType | null;
handle?: RouteObject["handle"];
shouldRevalidate?: ShouldRevalidateFunction;
lazy?: LazyRouteFunction;
}
Как получить свойство ? Я попытался использовать Hooks uselocation < /code> и
useParams Но никто не показал это свойство.
Мне нужно знать, может ли пользователь редактировать данные на странице. Наряду с информацией пользователя, доступ к страницам, например,: ["page1.fullaccess", "pag2.read", ...] < /p>
Я создал: < /p>
const Page1Component = lazy(() =>
import('./page1.ui').then((module) => ({ default: module.Page1 })),
);
const page1Route: RouteObject = {
id: 'Page1',
path: '/lalala',
element: createElement(enhance(Page1Component)),
};
< /code>
и < /p>
const browserRouter = createBrowserRouter([
{
errorElement: ,
children: [
{
element: createElement(enhance(GenericLayout)),
children: [
page1Route,
...
],
},
.....
< /code>
в крючке, который я вставляю на странице: < /p>
const useIsCan = () => {
const location = useLocation();
const params = useParams();
const { data, isLoading } = useQuery(getCurrentUserPropsQuery());
const isCanEdit =
data && data.roles.includes(`${The page ID should be here}.FullAccess`)
Подробнее здесь: https://stackoverflow.com/questions/796 ... properties