diff --git a/.eslintrc b/.eslintrc
index e9aa316..9ff57a3 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -1,47 +1,48 @@
{
- "env": {
- "browser": true,
- "es2021": true
- },
- "extends": [
- "eslint:recommended",
- "plugin:react/recommended",
- "plugin:react/jsx-runtime",
- "plugin:@typescript-eslint/recommended"
- ],
- "overrides": [],
- "parser": "@typescript-eslint/parser",
- "parserOptions": {
- "ecmaVersion": "latest",
- "sourceType": "module"
- },
- "plugins": [
- "react",
- "@typescript-eslint",
- "unused-imports",
- "simple-import-sort"
- ],
- "rules": {
- "no-unused-vars": "off",
- "unused-imports/no-unused-imports": "warn",
- "unused-imports/no-unused-vars": [
- "warn",
- {
- "vars": "all",
- "varsIgnorePattern": "^_",
- "args": "after-used",
- "argsIgnorePattern": "^_"
- }
+ "env": {
+ "browser": true,
+ "es2021": true
+ },
+ "extends": [
+ "eslint:recommended",
+ "plugin:react/recommended",
+ "plugin:react/jsx-runtime",
+ "plugin:@typescript-eslint/recommended",
+ "plugin:react-hooks/recommended"
],
- "simple-import-sort/imports": "warn",
- "simple-import-sort/exports": "warn",
- "react/react-in-jsx-scope": "off",
- "react/prop-types": "off",
- "@typescript-eslint/no-explicit-any": "off"
- },
- "settings": {
- "react": {
- "version": "detect"
+ "overrides": [],
+ "parser": "@typescript-eslint/parser",
+ "parserOptions": {
+ "ecmaVersion": "latest",
+ "sourceType": "module"
+ },
+ "plugins": [
+ "react",
+ "@typescript-eslint",
+ "unused-imports",
+ "simple-import-sort"
+ ],
+ "rules": {
+ "no-unused-vars": "off",
+ "unused-imports/no-unused-imports": "warn",
+ "unused-imports/no-unused-vars": [
+ "warn",
+ {
+ "vars": "all",
+ "varsIgnorePattern": "^_",
+ "args": "after-used",
+ "argsIgnorePattern": "^_"
+ }
+ ],
+ "simple-import-sort/imports": "warn",
+ "simple-import-sort/exports": "warn",
+ "react/react-in-jsx-scope": "off",
+ "react/prop-types": "off",
+ "@typescript-eslint/no-explicit-any": "off"
+ },
+ "settings": {
+ "react": {
+ "version": "detect"
+ }
}
- }
-}
\ No newline at end of file
+}
diff --git a/package.json b/package.json
index 8226b55..7c38bda 100644
--- a/package.json
+++ b/package.json
@@ -91,6 +91,7 @@
"coveralls": "^3.1.1",
"eslint": "^8.46.0",
"eslint-plugin-react": "^7.33.1",
+ "eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-storybook": "^0.6.13",
"eslint-plugin-unused-imports": "^3.0.0",
diff --git a/src/core/components/RouteGuard/index.tsx b/src/core/components/RouteGuard/index.tsx
index a4bb05a..b0d11ea 100644
--- a/src/core/components/RouteGuard/index.tsx
+++ b/src/core/components/RouteGuard/index.tsx
@@ -26,20 +26,18 @@ function RouteGuard(props: RouteGuardProps) {
const isInRouter = useInRouterContext();
- /* istanbul ignore if */
- if (!isInRouter) {
- console.warn(
- `请在 react-router-dom V6 的 组件中使用 Auth.${RouteGuard.name} 组件。如果你不是使用 V6 版本请不要使用这个组件。@see https://reactrouter.com/en/main/router-components/router。
- `
- );
- return <>{children}>;
- }
-
const location = useLocation();
const allowRoutes = useAuthData(routes, { authKey });
const isAllow = useMemo(() => {
- if (!routes) {
+ /* istanbul ignore if */
+ if (!isInRouter) {
+ console.warn(
+ `请在 react-router-dom V6 的 组件中使用 Auth.${RouteGuard.name} 组件。如果你不是使用 V6 版本请不要使用这个组件。@see https://reactrouter.com/en/main/router-components/router。
+ `
+ );
+ return true;
+ } else if (!routes) {
return true;
} else if (!allowRoutes) {
return false;
@@ -51,7 +49,7 @@ function RouteGuard(props: RouteGuardProps) {
} else {
return true;
}
- }, [location, allowRoutes]);
+ }, [isInRouter, routes, allowRoutes, location]);
return <>{isAllow ? children : NoAuthFallback}>;
}
diff --git a/src/core/hooks/useAuthData.ts b/src/core/hooks/useAuthData.ts
index 53e29a0..c41a6bf 100644
--- a/src/core/hooks/useAuthData.ts
+++ b/src/core/hooks/useAuthData.ts
@@ -27,15 +27,16 @@ const defaultOptions: Required = {
/** 获取根据权限过滤的集合 */
export function useAuthData(data?: any[], options?: Options) {
- /* istanbul ignore if */
- if (!Array.isArray(data)) {
- return data;
- }
const combineOptions = defaults(options, defaultOptions);
const { auth, disabled } = useContext(ProviderContext);
const { authProxy } = useContext(ProxyContext);
const { validator } = useContext(ValidatorContext);
+ /* istanbul ignore if */
+ if (!Array.isArray(data)) {
+ return data;
+ }
+
function filterFn(item: any) {
return (
!item[combineOptions.authKey] ||