Skip to content

Commit

Permalink
feat(views): ✨ [Pages] add 权限切换
Browse files Browse the repository at this point in the history
  • Loading branch information
jsxiaosi committed Dec 11, 2022
1 parent 7c98cb5 commit b345524
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
8 changes: 5 additions & 3 deletions src/Pages.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { RouteObject } from 'react-router-dom';
import { Navigate, useRoutes } from 'react-router-dom';
import { useState, useEffect, memo } from 'react';
import { baseRouter } from './router';
import { baseRouter, errorPage } from './router';
import { useAppSelector } from './store/hooks';
import { handlePowerRoute, handleRouteList } from './router/utils';

Expand All @@ -18,7 +18,7 @@ const Pages = memo(() => {
element: <Navigate to={routerList[0].path || ''} />,
});
}
return routerList;
return [...routerList, ...errorPage];
};

// 更新路由列表
Expand All @@ -27,13 +27,15 @@ const Pages = memo(() => {
baseRouter.map((i) => {
const routeItem = i;
if (routeItem.path === '/') {
routeItem.children?.push(...handleRedirect());
routeItem.children = handleRedirect();
}
return routeItem;
}),
);
}, [asyncRouter]);

console.log('route', route);

const routeElemt = useRoutes(route);

return <>{routeElemt}</>;
Expand Down
2 changes: 1 addition & 1 deletion src/layout/components/Sidebar/SidebarInline/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const Sidebar = memo(() => {
} else {
return menuList;
}
}, [sidebarMode, pathname]);
}, [sidebarMode, pathname, menuList]);

const MenuRender = (
<>
Expand Down
14 changes: 8 additions & 6 deletions src/router/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import Authority from '@/layout/Authority';
const ErrorPage403 = lazy(() => import('@/views/core/error/403'));
const Login = lazy(() => import('@/views/Login'));

export const errorPage = [
{
path: '*',
element: <ErrorPage403 />,
},
];

export const baseRouter: RouteObject[] = [
{
path: '/',
Expand All @@ -15,12 +22,7 @@ export const baseRouter: RouteObject[] = [
</Authority>
),
errorElement: <ErrorPage403 />,
children: [
{
path: '*',
element: <ErrorPage403 />,
},
],
children: [...errorPage],
},
{
path: '/login',
Expand Down
12 changes: 11 additions & 1 deletion src/views/Power/UseList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { Button } from 'antd';
import { initAsyncRoute } from '@/router/utils';

const UseList = () => {
return <>UseList</>;
const setCount = async () => {
initAsyncRoute('test');
};
return (
<Button type="primary" onClick={setCount}>
切换权限
</Button>
);
};

export default UseList;

0 comments on commit b345524

Please sign in to comment.