-
Notifications
You must be signed in to change notification settings - Fork 8.3k
fix: 修复在 hash 路由模式下无法在新窗口打开路由的问题 #6652
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
Conversation
此问题是由于 PR vbenjs#6583 中新增的 `resolveHref` 函数导致的。其在 hash 路由模式下,得到的 URL 会包含 #/ 前缀。在经过 openRouteInNewWindow 的逻辑后就会出现两次 /# 前缀
|
WalkthroughAdjusted URL assembly in openRouteInNewWindow to only prepend '/#' when a location.hash exists and the computed fullPath does not already start with '/#', preventing duplicate hash fragments. No API or export changes; rest of the function remains unchanged. Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant Utils as openRouteInNewWindow
participant Browser
Caller->>Utils: openRouteInNewWindow(route)
Utils->>Utils: compute fullPath (ensure leading '/')
alt location.hash exists AND fullPath not starting with '/#'
Utils->>Utils: prefix '/#' to fullPath
else
Utils->>Utils: keep fullPath as-is
end
Utils->>Browser: openWindow(url, target="_blank")
Browser-->>Caller: New tab/window opened
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/@core/base/shared/src/utils/window.ts (1)
30-35: RefactoropenRouteInNewWindowfor explicit hash-mode detectionUsing
location.hashtruthiness can misfire on non-router anchors (e.g.#section). Let’s only treat hashes beginning with#/as router mode:function openRouteInNewWindow(path: string) { const { hash, origin } = location; const fullPath = path.startsWith('/') ? path : `/${path}`; - const url = `${origin}${hash && !fullPath.startsWith('/#') ? '/#' : ''}${fullPath}`; + const isHashMode = hash.startsWith('#/'); // only true when hash-router is active + const needsHashPrefix = isHashMode && !fullPath.startsWith('/#'); + const url = `${origin}${needsHashPrefix ? '/#' : ''}${fullPath}`; openWindow(url, { target: '_blank' }); }Call sites have already been audited and correctly pass either a
fullPathor a pre-resolved href, so query parameters remain intact:
- packages/stores/src/modules/tabbar.ts →
openRouteInNewWindow(tab.fullPath || tab.path)- packages/effects/layouts/src/basic/menu/use-navigation.ts →
openRouteInNewWindow(resolveHref(path))
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
packages/@core/base/shared/src/utils/window.ts(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-02-08T07:05:28.825Z
Learnt from: dingdayu
PR: vbenjs/vue-vben-admin#5500
File: packages/stores/src/modules/tabbar.ts:557-559
Timestamp: 2025-02-08T07:05:28.825Z
Learning: In Vue Vben Admin, while tab identification uses `path` to group tabs with same path but different queries, router navigation operations (router.push) and new window operations should use `fullPath` to preserve the complete URL including query parameters. This applies specifically to:
1. Router navigation in tab maximize/restore feature
2. Opening tabs in new window via openTabInNewWindow
Applied to files:
packages/@core/base/shared/src/utils/window.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
- GitHub Check: Check (windows-latest)
- GitHub Check: Test (windows-latest)
- GitHub Check: Lint (ubuntu-latest)
- GitHub Check: Check (ubuntu-latest)
- GitHub Check: Lint (windows-latest)
- GitHub Check: post-update (windows-latest)
- GitHub Check: post-update (ubuntu-latest)
🔇 Additional comments (1)
packages/@core/base/shared/src/utils/window.ts (1)
33-33: Fix correctly prevents double '/#' in hash mode — LGTMConditionally injecting '/#' only when
location.hashexists andfullPathdoesn’t already start with'/#'resolves the duplicate prefix bug while keeping history-mode behavior intact.
此问题是由于 PR vbenjs#6583 中新增的 `resolveHref` 函数导致的。其在 hash 路由模式下,得到的 URL 会包含 #/ 前缀。在经过 openRouteInNewWindow 的逻辑后就会出现两次 /# 前缀
此问题是由于 PR #6583 中新增的
resolveHref函数导致的。其在 hash 路由模式下,得到的 URL 会包含 #/ 前缀。在经过 openRouteInNewWindow 的逻辑后就会出现两次 /# 前缀Description
Type of change
Please delete options that are not relevant.
pnpm-lock.yamlunless you introduce a new test example.Checklist
pnpm run docs:devcommand.pnpm test.feat:,fix:,perf:,docs:, orchore:.Summary by CodeRabbit