Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: 后端路由模式时,本地静态路由和后端路由合并 #4899

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

wdzyy
Copy link
Contributor

@wdzyy wdzyy commented Nov 15, 2024

Description

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Checklist

ℹ️ Check all checkboxes - this will indicate that you have done everything in accordance with the rules in CONTRIBUTING.

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs:dev command.
  • Run the tests with pnpm test.
  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new static menu system that combines static and dynamic menu items for improved navigation.
    • Added a structured routing system with defined routes for "Dashboard," "Analytics," "Workspace," and an "About" page.
  • Bug Fixes

    • Enhanced menu generation logic to ensure static menus are not mutated during dynamic menu integration.
  • Documentation

    • Updated comments and documentation for clarity on the merging of static and dynamic menus.

@wdzyy wdzyy requested review from anncwb, vince292007 and a team as code owners November 15, 2024 06:03
Copy link

changeset-bot bot commented Nov 15, 2024

⚠️ No Changeset found

Latest commit: 39e0e69

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Nov 15, 2024

Walkthrough

The changes involve modifications to the generateAccess function across multiple applications, enhancing the menu generation logic by merging static and dynamic menus. A new file defining static routes is introduced, which includes a staticMenuList and a demoRoute. The fetchMenuListAsync function is updated to combine these static routes with dynamically fetched menus, ensuring that the static menu list is deeply cloned to prevent mutation.

Changes

File Path Change Summary
apps/web-antd/src/router/access.ts Modified generateAccess to merge static and dynamic menus; added import for cloneDeep and staticMenuList.
apps/web-antd/src/router/routes/static.ts Introduced static routes and staticMenuList; added demoRoute for modular route management.
apps/web-ele/src/router/access.ts Updated generateAccess to include staticMenuList with dynamic menus; added import for cloneDeep.
apps/web-ele/src/router/routes/static.ts Created static routes file with staticMenuList and demoRoute; structured routes for navigation and localization.
apps/web-naive/src/router/access.ts Altered generateAccess to integrate staticMenuList with dynamic menus; included import for cloneDeep.
apps/web-naive/src/router/routes/static.ts Added static routes file with staticMenuList and demoRoute; defined routes with metadata for navigation.

Possibly related PRs

Suggested labels

chore

Suggested reviewers

  • vince292007
  • anncwb

Poem

🐰 In the code where menus blend,
Static and dynamic, hand in hand,
A rabbit hops through routes anew,
With paths and icons, all in view.
Cloned and merged, the lists align,
A joyful dance of code divine! 🌟

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

apps/web-antd/src/router/access.ts

Oops! Something went wrong! :(

ESLint: 9.14.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/node_modules/@vben/eslint-config/dist/index.mjs' imported from /eslint.config.mjs
at finalizeResolution (node:internal/modules/esm/resolve:257:11)
at moduleResolve (node:internal/modules/esm/resolve:914:10)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Outside diff range and nitpick comments (12)
apps/web-ele/src/router/access.ts (1)

37-38: Translate comment to English for better collaboration.

The Chinese comment "本地菜单和动态菜单合并" should be in English.

-      // 本地菜单和动态菜单合并
+      // Merge local static menus with dynamic menus
apps/web-antd/src/router/access.ts (1)

35-38: Consider performance optimizations and error handling

The current implementation could benefit from the following architectural improvements:

  1. Cache the deep-cloned static menu list to avoid redundant cloning operations
  2. Add proper error handling for failed dynamic menu fetches
  3. Consider implementing a retry mechanism for dynamic menu fetches

Consider implementing these improvements:

// Cache the cloned static menus
const cachedStaticMenus = cloneDeep(staticMenuList);

async function fetchMenuListAsync() {
  try {
    const dynamicMenus = await getAllMenusApi();
    return [...cachedStaticMenus, ...dynamicMenus];
  } catch (error) {
    message.error($t('common.fetchMenuError'));
    // Fallback to static menus only
    return cachedStaticMenus;
  }
}
apps/web-antd/src/router/routes/static.ts (4)

5-7: Consider adding English documentation

The file's purpose is documented in Chinese. Consider adding English documentation or making it bilingual for better international collaboration.

 /**
- * 该文件放非后台返回的前端静态路由
+ * This file contains frontend static routes that are not returned from the backend
+ * 该文件放非后台返回的前端静态路由
  */

45-45: Standardize translation key format

The meta.title values use inconsistent formats:

  • 'page.dashboard.title' (direct key)
  • 'page.dashboard.analytics' (direct key)
  • 'page.dashboard.workspace' (direct key)

Consider using the $t() function consistently for all titles, similar to how it's used in the demo route.

   meta: {
     icon: 'lucide:layout-dashboard',
     order: -1,
-    title: 'page.dashboard.title',
+    title: $t('page.dashboard.title'),
   },
   // ... and similar changes for other titles

Also applies to: 58-58, 68-68


72-72: Consider using deep clone for demo routes

When spreading demoRoute, consider using a deep clone to prevent potential mutations if the array is used elsewhere.

-  ...demoRoute,
+  ...JSON.parse(JSON.stringify(demoRoute)),

1-73: Consider documenting route merging strategy

Since this file defines static routes that will be merged with backend routes (as per PR objective), consider:

  1. Adding documentation about the merging strategy
  2. Implementing conflict resolution for duplicate routes
  3. Defining clear priorities between static and backend routes

This will help prevent potential routing conflicts and make the system's behavior more predictable.

apps/web-ele/src/router/routes/static.ts (2)

5-7: Consider adding English translations for documentation

While the Chinese comment "该文件放非后台返回的前端静态路由" clearly explains the file's purpose, consider adding English translations to improve international collaboration.

 /**
- * 该文件放非后台返回的前端静态路由
+ * 该文件放非后台返回的前端静态路由
+ * This file contains frontend static routes that are not returned by the backend
  */

39-71: Standardize the translation key pattern

There's an inconsistency in how translations are handled:

  • Some use direct $t() calls (in demoRoute)
  • Others use translation keys (e.g., 'page.dashboard.title')

Consider standardizing to use translation keys throughout for better maintainability.

   {
     component: 'BasicLayout',
     meta: {
       icon: 'lucide:layout-dashboard',
       order: -1,
-      title: 'page.dashboard.title',
+      title: $t('page.dashboard.title'),
     },
     // ... rest of the configuration
   }
apps/web-naive/src/router/routes/static.ts (4)

5-7: Consider adding English documentation

The file's purpose is documented in Chinese. Consider adding English documentation or making it bilingual for better international collaboration.

 /**
- * 该文件放非后台返回的前端静态路由
+ * This file contains frontend static routes that are not returned from the backend
+ * 该文件放非后台返回的前端静态路由
  */

45-45: Ensure consistent internationalization usage

The title uses a direct string 'page.dashboard.title' instead of the $t function used elsewhere in the file.

-      title: 'page.dashboard.title',
+      title: $t('page.dashboard.title'),

56-56: Document the affixTab property

The affixTab property is only used in the analytics route. Consider adding a comment explaining its purpose and why it's specifically needed here.

       meta: {
+        // Indicates that this tab should be pinned in the tab bar
         affixTab: true,
         icon: 'lucide:area-chart',

1-73: Document the route merging strategy

While this file clearly defines static routes, it would be helpful to document how these routes will be merged with backend routes. Consider adding a comment explaining:

  1. The merging strategy
  2. How route conflicts are resolved
  3. The order of precedence between static and backend routes
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 788a29a and 39e0e69.

📒 Files selected for processing (6)
  • apps/web-antd/src/router/access.ts (2 hunks)
  • apps/web-antd/src/router/routes/static.ts (1 hunks)
  • apps/web-ele/src/router/access.ts (2 hunks)
  • apps/web-ele/src/router/routes/static.ts (1 hunks)
  • apps/web-naive/src/router/access.ts (2 hunks)
  • apps/web-naive/src/router/routes/static.ts (1 hunks)
🔇 Additional comments (8)
apps/web-naive/src/router/access.ts (2)

36-36: Consider the menu merging order

The current implementation places static menus before dynamic ones. Please verify if this order aligns with the expected menu structure and navigation hierarchy.

#!/bin/bash
# Description: Check for any existing menu order specifications or related configurations

# Look for menu-related configurations
rg -g '!*.{lock,min.js}' -i "menu.*order|menu.*priority|menu.*position"

# Check for any documentation about menu structure
fd -g "README*" -X rg -l "menu"

8-8: Verify the static routes implementation

The imports look correct, but let's verify the structure and exports of the static routes file.

Also applies to: 15-15

✅ Verification successful

Import and static routes implementation verified

The verification confirms:

  • The static routes file exists at apps/web-naive/src/router/routes/static.ts
  • staticMenuList is properly exported and used in access.ts
  • The implementation shows correct usage with cloneDeep to prevent mutations when merging with dynamic menus
  • The static menu structure follows the expected format with component, meta, and order properties
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the static routes file exists and exports the required entities

# Check if the static routes file exists
fd -p "routes/static\.(ts|js)" apps/web-naive/src/router

# Verify the exports
ast-grep --pattern 'export const staticMenuList = $_'

Length of output: 699


Script:

#!/bin/bash
# Let's try a different approach to verify the static routes implementation

# Check for any file containing "static" in the router directory
fd -p "static" apps/web-naive/src/router

# Search for staticMenuList declaration in the codebase
rg "staticMenuList" apps/web-naive/src/router -A 5

# Look for menu-related type definitions that might help understand the structure
rg "type.*Menu" apps/web-naive/src/router

Length of output: 1504

apps/web-ele/src/router/access.ts (2)

8-8: LGTM! Imports are well organized.

The new imports for cloneDeep and staticMenuList are appropriately placed and necessary for the menu merging functionality.

Also applies to: 16-16


36-38: Verify menu structure compatibility.

Please ensure that the structure of static and dynamic menus is compatible to prevent runtime errors.

✅ Verification successful

Let me try to find the correct paths and check the menu structures.


Let me check the static menu structure and the API response structure to verify compatibility.


Menu structures are compatible and type-safe

The verification shows that both static and dynamic menus use the same type RouteRecordStringComponent[]:

  • Static menus are explicitly typed as RouteRecordStringComponent[] in static.ts
  • Dynamic menus from getAllMenusApi() return the same type RouteRecordStringComponent[]
  • Both follow the base menu type definition from menu-record.ts which ensures consistent structure with properties like path, meta, children, etc.

The merge operation using [...cloneDeep(staticMenuList), ...dynamicMenus] is safe as both arrays contain compatible objects.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check menu structure consistency between static and dynamic menus

# Check static menu structure
echo "Checking static menu structure..."
ast-grep --pattern 'export const staticMenuList = $_' ./router/routes/static.ts

# Check dynamic menu structure from API response type definitions
echo "Checking API response structure..."
ast-grep --pattern 'interface $_Response {
  $$$
}'

Length of output: 364


Script:

#!/bin/bash
# First, let's find the correct paths for static menu and API files
echo "Finding static menu file..."
fd -t f "static.ts"

echo "\nFinding menu-related files..."
fd -t f -e ts | rg -i "menu"

echo "\nChecking menu-related type definitions..."
rg -A 5 "interface.*Menu" 

Length of output: 14186


Script:

#!/bin/bash
# Check static menu structure in the correct file
echo "Static menu structure:"
cat apps/web-ele/src/router/routes/static.ts

echo "\nAPI response structure:"
cat apps/web-ele/src/api/core/menu.ts

echo "\nChecking base menu type definition:"
cat packages/@core/base/typings/src/menu-record.ts

Length of output: 3083

apps/web-antd/src/router/access.ts (1)

8-8: Verify the static routes implementation

The introduction of staticMenuList creates a new dependency. We should verify its implementation to ensure it follows the same structure as the dynamic menus.

Also applies to: 16-16

✅ Verification successful

Let me verify the static routes implementation by searching for it in the codebase.


Let me check the implementation of the static routes to verify its structure.


Based on the code inspection, I can now provide a final response:

Static routes implementation is properly structured

The static routes implementation in static.ts follows the correct structure:

  • Uses the same RouteRecordStringComponent type as dynamic routes
  • Properly implements meta fields (icon, order, title)
  • Follows nested route structure with children
  • Includes all necessary fields for menu generation (component, meta, name, path)

The use of cloneDeep from @vben/utils is appropriate here as it prevents mutations when merging static and dynamic menus.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the structure of static routes matches dynamic routes

# Check the structure of static routes
echo "Checking static routes structure..."
rg -A 10 "staticMenuList.*=" "./apps/web-antd/src/router/routes/static"

# Check if the static routes follow the same interface as dynamic routes
echo "Checking menu interface usage..."
ast-grep --pattern 'interface $MENU_TYPE {
  $$$
}'

Length of output: 127229


Script:

#!/bin/bash
# Search for static routes implementation
echo "Searching for static routes implementation..."
rg -A 5 "staticMenuList" apps/web-antd/src/router/

# Check if there are any route-related files in the router directory
echo -e "\nChecking router directory structure..."
fd . apps/web-antd/src/router/

Length of output: 2035


Script:

#!/bin/bash
# Check the full implementation of static routes
echo "Checking static routes implementation..."
cat apps/web-antd/src/router/routes/static.ts

# Check the menu interface to verify structure compatibility
echo -e "\nChecking menu interfaces..."
rg -A 5 "interface.*Menu" apps/web-antd/src/router/

Length of output: 1716

apps/web-antd/src/router/routes/static.ts (1)

25-25: Verify the component path convention

The component path /_core/about/index starts with an underscore. Verify if this follows the project's conventions for internal/private components.

✅ Verification successful

Let me check the contents of these _core directories and their usage pattern to make a more informed decision.


Component path convention is consistent across the project

The /_core/about/index path follows the established convention in the project. This pattern is consistently used across all web apps (antd, ele, naive) and is also documented in the project's route documentation. The underscore prefix is intentionally used to organize core/internal components, as evidenced by:

  • Consistent _core directory structure in all web apps under src/views/
  • Same component path pattern in both static and module routes
  • Usage in official documentation examples
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for other component paths starting with underscore
fd -e ts -e tsx -e vue | xargs rg "component:.*['\"]/_.*['\"]" -l

# Check if _core directory exists and its structure
fd -t d "_core"

Length of output: 334


Script:

#!/bin/bash
# Check the structure and contents of _core directories
fd . "apps/*/src/views/_core" -t f

# Check for any documentation about _core convention
rg -i "(_core|core|internal)" "README.md" -A 2 -B 2

# Look for similar route patterns across different web apps
rg "component:.*/_core/about" -A 2 -B 2

Length of output: 3683

apps/web-ele/src/router/routes/static.ts (1)

39-73: Well-structured route configuration

The static menu configuration follows Vue Router best practices:

  • Proper use of meta properties for customization
  • Clear hierarchy with BasicLayout and child routes
  • Effective use of route ordering
  • Modular integration of demo routes
apps/web-naive/src/router/routes/static.ts (1)

22-30: Review path consistency and component path convention

A few concerns about the route configuration:

  1. The parent path is /about but the child path is /vben-admin/about, which seems inconsistent
  2. The component path /_core/about/index uses an underscore prefix, which typically indicates internal/private paths

Consider:

  1. Making the paths hierarchically consistent
  2. Reviewing if this component should be in a private directory
✅ Verification successful

Based on the search results, I can now generate the final response:

Path structure and component location are consistent with project conventions

The search results show that:

  1. The path /vben-admin/about is consistently used across all web app variants (antd, naive, ele) in their route configurations
  2. The /_core directory is a standard location for core components, containing authentication, fallback, and about pages across the project

No changes needed as both the path structure and component location follow established project patterns.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for other routes using similar path patterns
rg -g '*.{ts,js,vue}' '/vben-admin/about|/_core/'

Length of output: 5408

Comment on lines +34 to +36
const dynamicMenus = await getAllMenusApi();
// 本地菜单和动态菜单合并
return [...cloneDeep(staticMenuList), ...dynamicMenus];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling and translate comment

  1. Consider adding error handling for getAllMenusApi() to gracefully handle API failures.
  2. The Chinese comment should be translated to English for consistency.

Apply this diff:

-      const dynamicMenus = await getAllMenusApi();
-      // 本地菜单和动态菜单合并
-      return [...cloneDeep(staticMenuList), ...dynamicMenus];
+      try {
+        const dynamicMenus = await getAllMenusApi();
+        // Merge local static menus with dynamic menus
+        return [...cloneDeep(staticMenuList), ...dynamicMenus];
+      } catch (error) {
+        message.error(`${$t('common.loadingMenuFailed')}`);
+        console.error('Failed to fetch dynamic menus:', error);
+        // Fallback to static menus only
+        return cloneDeep(staticMenuList);
+      }

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +36 to +38
const dynamicMenus = await getAllMenusApi();
// 本地菜单和动态菜单合并
return [...cloneDeep(staticMenuList), ...dynamicMenus];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling for getAllMenusApi.

The API call could fail, but there's no error handling. Consider adding try-catch to handle potential failures gracefully.

-      const dynamicMenus = await getAllMenusApi();
-      // 本地菜单和动态菜单合并
-      return [...cloneDeep(staticMenuList), ...dynamicMenus];
+      try {
+        const dynamicMenus = await getAllMenusApi();
+        // Merge local static menus with dynamic menus
+        return [...cloneDeep(staticMenuList), ...dynamicMenus];
+      } catch (error) {
+        ElMessage.error($t('common.menuLoadError'));
+        console.error('Failed to load dynamic menus:', error);
+        // Fallback to static menus only
+        return cloneDeep(staticMenuList);
+      }

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +36 to +38
const dynamicMenus = await getAllMenusApi();
// 本地菜单和动态菜单合并
return [...cloneDeep(staticMenuList), ...dynamicMenus];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider adding validation and deduplication logic

The current implementation merges static and dynamic menus without validation. This could lead to:

  1. Duplicate menu items if the same routes exist in both lists
  2. Potential conflicts in menu hierarchy
  3. Performance impact from deep cloning large menu structures

Consider implementing the following improvements:

- return [...cloneDeep(staticMenuList), ...dynamicMenus];
+ const staticMenus = cloneDeep(staticMenuList);
+ // Validate menu structure
+ const validatedDynamicMenus = validateMenuStructure(dynamicMenus);
+ // Remove duplicates based on route path or menu key
+ const uniqueMenus = deduplicateMenus(staticMenus, validatedDynamicMenus);
+ return uniqueMenus;

Consider translating the Chinese comment to English for consistency:

- // 本地菜单和动态菜单合并
+ // Merge local static menus with dynamic menus
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const dynamicMenus = await getAllMenusApi();
// 本地菜单和动态菜单合并
return [...cloneDeep(staticMenuList), ...dynamicMenus];
const dynamicMenus = await getAllMenusApi();
// Merge local static menus with dynamic menus
return [...cloneDeep(staticMenuList), ...dynamicMenus];

Comment on lines +22 to +30
path: '/about',
children: [
{
component: '/_core/about/index',
meta: {
title: $t('demos.vben.about'),
},
name: 'VbenAbout',
path: '/vben-admin/about',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Review path inconsistency

The parent route path is /about but the child route path is /vben-admin/about. This inconsistency might cause routing issues.

   path: '/about',
   children: [
     {
       component: '/_core/about/index',
       meta: {
         title: $t('demos.vben.about'),
       },
       name: 'VbenAbout',
-      path: '/vben-admin/about',
+      path: 'index',
     },
   ],
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
path: '/about',
children: [
{
component: '/_core/about/index',
meta: {
title: $t('demos.vben.about'),
},
name: 'VbenAbout',
path: '/vben-admin/about',
path: '/about',
children: [
{
component: '/_core/about/index',
meta: {
title: $t('demos.vben.about'),
},
name: 'VbenAbout',
path: 'index',

Comment on lines +12 to +34
const demoRoute: RouteRecordStringComponent[] = [
{
component: 'BasicLayout',
meta: {
hideChildrenInMenu: true,
icon: 'lucide:copyright',
order: 9999,
title: $t('demos.vben.about'),
},
name: 'About',
path: '/about',
children: [
{
component: '/_core/about/index',
meta: {
title: $t('demos.vben.about'),
},
name: 'VbenAbout',
path: '/vben-admin/about',
},
],
},
];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix inconsistent route path structure

The current path structure might cause routing issues:

  • Parent path is /about
  • Child path is /vben-admin/about
  • Child path should extend the parent path pattern

Also, hideChildrenInMenu: true might be unnecessary since there's only one child route.

Consider this fix:

 const demoRoute: RouteRecordStringComponent[] = [
   {
     component: 'BasicLayout',
     meta: {
-      hideChildrenInMenu: true,
       icon: 'lucide:copyright',
       order: 9999,
       title: $t('demos.vben.about'),
     },
     name: 'About',
-    path: '/about',
+    path: '/vben-admin',
     children: [
       {
         component: '/_core/about/index',
         meta: {
           title: $t('demos.vben.about'),
         },
         name: 'VbenAbout',
         path: '/vben-admin/about',
       },
     ],
   },
 ];
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const demoRoute: RouteRecordStringComponent[] = [
{
component: 'BasicLayout',
meta: {
hideChildrenInMenu: true,
icon: 'lucide:copyright',
order: 9999,
title: $t('demos.vben.about'),
},
name: 'About',
path: '/about',
children: [
{
component: '/_core/about/index',
meta: {
title: $t('demos.vben.about'),
},
name: 'VbenAbout',
path: '/vben-admin/about',
},
],
},
];
const demoRoute: RouteRecordStringComponent[] = [
{
component: 'BasicLayout',
meta: {
icon: 'lucide:copyright',
order: 9999,
title: $t('demos.vben.about'),
},
name: 'About',
path: '/vben-admin',
children: [
{
component: '/_core/about/index',
meta: {
title: $t('demos.vben.about'),
},
name: 'VbenAbout',
path: '/vben-admin/about',
},
],
},
];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants